-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add node_notify signal for animation trees #102165
base: master
Are you sure you want to change the base?
Conversation
See also:
As I have pointed out in the past with those, it should be implemented so that the ancestor StateMachine returns the nested paths when in Grouped mode (https://godotengine.org/article/migrating-animations-from-godot-4-0-to-4-3/#grouped). In other words, it must be implemented in such a way that the signal is propagated to the ancestor State as special case for the Grouped mode. |
Thanks for the links, I hadn't seen those PRs. Do you think it would be worth adding
I'll work on adding this. Just to be sure I understand correctly, the changes I'll make would change the example root sm
Also regarding a comment you left on another PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the links, I hadn't seen those PRs. Do you think it would be worth adding fading_from_state_changed to this pr?
I think so.
As for the StateMachinePlayback
object, it should be a unique resource for each AnimationTree, so there should be no problem to fire a signal there.
However, if you want to fire a signal in the AnimationNode, signals should not be registered with AnimationNode as explained in the review below.
The simplest implementation would be to fire signal from the AnimationTree with its own BlendTree path. In this case, you can refer to AnimationTree::set_parameter()
to get the path. At this point, it may be better to separate the method for obtaining its own path from it and make it reusable.
But then, my concern is that each time we have more signals that we want to fire in the AnimationNode, we need to register all of them in the AnimationTree.
So, instead of adding a signal called oneshot_finished()
to the AnimationTree, we should add a generic abstract signal such as node_notified(animation_node_path, signal_name, signal_variants)
.
However, that PR should be a separate PR from the StateMachinePlayback
signal addition.
06a3c9d
to
89dbc1c
Compare
I've updated the pr to have Edit: One thing I'd like feedback on with the current code is if the signal emission should be put behind a call_deferred in all cases? I noticed it was like that for animation_started/animation_finished but wasn't sure if it should also be the case for the new signals. Easy change, just unsure what the preferred behavior would be. |
89dbc1c
to
4b9850a
Compare
This pr is currently sitting at +124 -11 which imo is a good size but if you'd prefer I can break this up into two PRs (maybe a third to rename |
4b9850a
to
e09355a
Compare
2c7c814
to
4059858
Compare
4059858
to
df98559
Compare
df98559
to
e13e26a
Compare
e13e26a
to
dcdd47a
Compare
enum AnimationNodeNotification { | ||
ANIMATION_NODE_NOTIFICATION_STARTED, | ||
ANIMATION_NODE_NOTIFICATION_FINISHED, | ||
ANIMATION_NODE_NOTIFICATION_FADEOUT_STARTED | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the overall implementation is headed in the right direction.
My concern is where to define the enum for signal, maybe it should be better that defined separately for each AnimationNode and returned as an int and AnimationNode class name in the AnimationTree like:
animation_tree.cpp
ADD_SIGNAL(MethodInfo(SceneStringName(animation_node_notification), PropertyInfo(Variant::STRING_NAME, "animation_node_path"), PropertyInfo(Variant::STRING_NAME, "animation_node_class_name"), PropertyInfo(Variant::INT, "what")));
animation_blend_tree.h
enum AnimationNodeNotificationOneShot {
ANIMATION_NODE_NOTIFICATION_ONESHOT_STARTED,
ANIMATION_NODE_NOTIFICATION_ONESHOT_FINISHED,
ANIMATION_NODE_NOTIFICATION_FADEOUT_FINISHED_INTERNAL, // Fadeout started.
};
~~~~~~
enum AnimationNodeTransitionNotification {
ANIMATION_NODE_NOTIFICATION_TRANSITION_STARTED,
ANIMATION_NODE_NOTIFICATION_TRANSITION_FINISHED,
};
This way, you can write enum documentation for each AnimationNode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was thinking about this. The meaning of some of the notifications are frustratingly similar but I agree it's probably best to separate them for clarity and ease of documentation.
@@ -991,6 +1001,7 @@ void AnimationTree::_bind_methods() { | |||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "anim_player", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "AnimationPlayer"), "set_animation_player", "get_animation_player"); | |||
|
|||
ADD_SIGNAL(MethodInfo(SNAME("animation_player_changed"))); | |||
ADD_SIGNAL(MethodInfo(SceneStringName(node_notification), PropertyInfo(Variant::STRING_NAME, "node"), PropertyInfo(Variant::INT, "what"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ADD_SIGNAL(MethodInfo(SceneStringName(node_notification), PropertyInfo(Variant::STRING_NAME, "node"), PropertyInfo(Variant::INT, "what"))); | |
ADD_SIGNAL(MethodInfo(SceneStringName(animation_node_notification), PropertyInfo(Variant::STRING_NAME, "animation_node_path"), PropertyInfo(Variant::INT, "what"))); |
"node" should be avoided because it is confusing with Node/Node2D/Node3D classes.
Closes godotengine/godot-proposals#10253.
Related to #102398
This adds
node_notify(StringName, NotifyReason)
toAnimationTree
as a generic signal used for node state changes during processing/playback. CurrentlyNotifyReason
can be eitherNOTIFY_STARTED
orNOTIFY_FINISHED
and is implemented for one shot and state machine nodes. For example in the following blend tree:The new signal fires with the following values: