duplicate signal connections fix in state machine

This commit is contained in:
yuki 2025-11-14 23:00:23 -03:00
parent 4b21537f52
commit a780839f4a

View file

@ -11,8 +11,9 @@ class_name StateMachine extends Node
func _ready() -> void:
for state_node: State in find_children("*", "State"):
# 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("")
@ -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.")