class_name ConditionalSpawnGroup extends DeferredSpawnGroup var condition: String var dynamic := false @onready var _exprobj := Expression.new() func _ready() -> void: super() _build_expr() _try_spawn_or_despawn() func _physics_process(_delta: float) -> void: if dynamic: _try_spawn_or_despawn() func _build_expr() -> void: if _exprobj.parse(condition) != OK: push_error(( "Couldn't parse condition `%s` " + "for conditional spawn group %s: %s" ) % [ condition, self, _exprobj.get_error_text() ]) dissolve() func _try_spawn_or_despawn() -> void: var belongs: bool = not not _exprobj.execute([], Storyboard.save_data) if _exprobj.has_execute_failed(): push_error(( "Couldn't evaluate condition `%s` " + "for conditional spawn group %s: %s" ) % [ condition, self, _exprobj.get_error_text() ]) queue_free() elif belongs: spawn() elif not belongs: despawn() if not dynamic: dissolve()