godot
godot copied to clipboard
Implement add custom animation nodes.
The document descripte that allow us to create custom AnimationNode.
Animation Tree Editors allow to load a animation node's resource, but it is quite inconvenient.
I found that the AnimationNodeBlendTreeEditor has methods add_custom_type() and remove_custom_type() to handle custom AnimationNode which be implemented by script, but they are never used.
And I found that AnimationNodeBlendSpace1DEditor, AnimationNodeBlendSpace2DEditor and AnimationNodeStateMachineEditor are get avaliable AnimationRootNode by ClassDB.
So, I let AnimationNodeBlendTreeEditor to get AnimationNodes by ClassDB, too.
And allow using EditorPlugin.add_custom_type() to add custom AnimationNode which be implemented by script.
Now, we can add custom AnimationNode by using GDExtension or EditorPlugin.

I think this merits a proposal first?
I think only this PR is not meaningful, since it is not enough to implement for extending. It may be possible to create the custom AnimationNode as class, but I suspect that we could not actually override the process.
virtual double process(double p_time, bool p_seek, bool p_is_external_seeking) override;
Each AnimationNode does its own processing by overriding this function, ~~but since it is not bound to GDVIRTUAL, it is not possible to add processing here in GDScript/GDExtension.~~ It seems to be bound.
But, even if it were bound to GDVIRTUAL, it would be processed in-game, but it would not be processed correctly in the editor. I am not too familiar with this, but due to this limitation, I had to implement the realtime retarget module as a custom module and do a virutual override on the cpp.
So, it would be nice if these animation features could be extended as GDExtention like a custom physics engine, but a proposal would need to be made first.
I'll test them again later in more detail. Perhaps we should send it to 4.1, but I hope we can accommodate this PR in some way.
I have interest in this, but we have to design the feature first.
If we extend only the base class AnimationNode, then this PR is fine, but if we extend a class like AnimationNodeAdd2, then it is not enough. For example, if you have a functionality similar to AnimationNodeAdd2, but want to change the functionality a little bit, you need to duplicate most of the methods from AnimationNodeAdd2 with extending AnimationNode, since you can't extend AnimationNodeAdd2 (AnimationNodeAdd2::process() doesn't call GDVIRTUAL_CALL currently).
So I think the following implementation is necessary, but there is a performance concern.
double AnimationNodeAdd2::process(double p_time, bool p_seek, bool p_is_external_seeking) {
double ret = -1;
GDVIRTUAL_CALL(_process, p_time, p_seek, p_is_external_seeking, ret);
if (ret != -1) {
return ret; // Virtual process is existing.
}
// Fallback built-in process.
double amount = get_parameter(add_amount);
double rem0 = blend_input(0, p_time, p_seek, p_is_external_seeking, 1.0, FILTER_IGNORE, sync);
blend_input(1, p_time, p_seek, p_is_external_seeking, amount, FILTER_PASS, sync);
return rem0;
}
The fundamental problem is that the GDVIRTUAL fallback method cannot be placed in the Godot core without hackey way like above. In any case, I feel that a proposal is needed that would make it easier to extend the Animation features.
I think this PR just provide an ability to collect AnimationNode for AnimationNodeBlendTreeEditor by using ClassDB and EditorPlugin::add_custom_type(). In othe word, it focus on "how to add" instead of "how to implement" a custom AnimationNode.
I think we need a proposal to discussion how to implement a custom AnimationNode, too.
But I have not idea for this topic.
I have sent #69802, which in combination with this PR should allow us to extend AnimationNode as we want.
It seems that registration to the state machine editor is not working. Is any commit missing?

It seems that registration to the state machine editor is not working. Is any commit missing?
![]()
Add custom animation nodes from Editor plugin only implement for AnimationNodeBlendTreeEditor currently.
But can add them from GDExtension.
~~If it is nessary, I will implement add from Editor Plugin for all AnimationTreeNodeEditorPlugin.~~
Now, I implement add custom animation nodes by using EditorPlugin for all AnimationTreeNodeEditorPlugin.