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,8 +11,9 @@ class_name StateMachine extends Node
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
for state_node: State in find_children("*", "State"):
|
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)
|
state_node.finished.connect(_transition_to_next_state)
|
||||||
|
|
||||||
await owner.ready
|
await owner.ready
|
||||||
state.enter("")
|
state.enter("")
|
||||||
|
|
||||||
|
|
@ -39,8 +40,8 @@ func _get_initial_state() -> State:
|
||||||
## Transitions the active state out after receiving a finished signal.
|
## Transitions the active state out after receiving a finished signal.
|
||||||
func _transition_to_next_state(target_state_path: String, data: Dictionary = {}) -> void:
|
func _transition_to_next_state(target_state_path: String, data: Dictionary = {}) -> void:
|
||||||
print("+++ TRANSITION CALLED: ", target_state_path)
|
print("+++ TRANSITION CALLED: ", target_state_path)
|
||||||
print("+++ Has node? ", has_node(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("+++ 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.")
|
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