Add node changed/started/finished signals for animation trees #102165
+60
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes godotengine/godot-proposals#10253. Open to changing how this works, this is a naive approach having underestimated the complexity of the animation tree code.
This specifically adds the following signals:
node_changed(node)
toAnimationNodeStateMachinePlayback
, emitted each time the current node is setnode_started(node)
toAnimationTree
, emitted specifically when a OneShot or StateMachine animation node startsnode_finished(node)
toAnimationTree
, same as above but when the node finishesIn the case of
node_started
andnode_finished
, I'm not sure if there's a better place to put the signals given the restrictions on which nodes they emit for. It would be easy to add emission for animation nodes as well, but I think the other node types don't necessarily make sense with started/finished semantics. Additionally, if a one shot node receives an abort request it does not currently emitnode_finished
but that could be easily changed.Another detail I wasn't sure about was currently the node to name lookup is a linear scan within the blend tree so to avoid that (and a Ref check for blend tree specifically) for each signal emission I set the resource name to the name assigned within the blend tree. This has a side effect where if a resource name is manually set on a nested state machine, any containing blend tree will emit signals for that node as well. This does mean there's a string to StringName conversion in the current state. This can be removed/changed if desired. I think it would be reasonable to add a StringName field to the animation node and remove the ChildNode struct but that is a larger change.
In the following example, a one-shot triggers a state machine which itself contains another state machine:
MyStateMachine:
InternalStateMachine:
Connecting all of the new signals to some printouts results in this order of operations:
Enabling crossfade works for all nodes involved, but does change the order certain things emit. For example with 0.1s crossfade on all connections the inner state machine finishes after the outer one has moved to the next node as expected: