diff --git a/scenes/classes/state_machine.gd b/scenes/classes/state_machine.gd index 6286750..d773d4c 100644 --- a/scenes/classes/state_machine.gd +++ b/scenes/classes/state_machine.gd @@ -11,10 +11,11 @@ class_name StateMachine extends Node func _ready() -> void: for state_node: State in find_children("*", "State"): - state_node.finished.connect(_transition_to_next_state) - - await owner.ready - state.enter("") + # fixes duplicate connections (not sure why) + if not state_node.finished.is_connected(_transition_to_next_state): + state_node.finished.connect(_transition_to_next_state) + await owner.ready + state.enter("") func _unhandled_input(event: InputEvent) -> void: @@ -39,8 +40,8 @@ func _get_initial_state() -> State: ## Transitions the active state out after receiving a finished signal. func _transition_to_next_state(target_state_path: String, data: Dictionary = {}) -> void: print("+++ TRANSITION CALLED: ", target_state_path) - print("+++ Has node? ", has_node(target_state_path)) - print("+++ All children: ", get_children().map(func(c: Node) -> StringName: return c.name)) + print("+++ has node? ", has_node(target_state_path)) + print("+++ all children: ", get_children().map(func(c: Node) -> StringName: return c.name)) assert(has_node(target_state_path), owner.name + ": Trying to transition to state " + target_state_path + " but it does not exist.")