duplicate signal connections fix in state machine
This commit is contained in:
parent
4b21537f52
commit
a780839f4a
1 changed files with 7 additions and 6 deletions
|
|
@ -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.")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue