godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Animation Blend Tree Expression Nodes #8657

Open SaracenOne opened 5 months ago

SaracenOne commented 5 months ago

Describe the project you are working on

3D virtual world system with VR and avatars.

Describe the problem or limitation you are having in your project

There is currently an inconsistency regarding the workflow of dealing with parameters for AnimationTrees. We have the concept of a base expression node in the AnimationTree. This allows state machines to perform expression evaluations in order to determine whether a state machine transition should occur. However, we have no equivalent of this for driving the parameters of blend trees. Instead we are forced to manually drive parameters externally via scripts. This can become a problem if we have a large blend tree or multiple blend trees and would like to reuse a small number of parameters to drive a large number of things.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

My proposal is introducing two main elements to the AnimationTree:

An AnimationNodeExpression type intended to be used inside of blend trees where you can type a formula which returns a value which can then be fed into a parameter directly.

The ability to set AnimationNode parameters as having an associated connection plug which accepts the output of AnimationNodeExpression node.

This approach provide continuity with expression evaluations in the StateMachine and will work a similar way, except rather than outputting a simple boolean true/false result, it can return values like floats or vectors which could then be fed into things timescale nodes or blend nodes in order to interpret the logic inside the tree itself. It will appear similar to the expression nodes used in the VisualShader editor.

This approach represents the ability to use animation trees in a more reusable self-driven capacity and should make them considerably more useful. This is a much more common workflow for artists since the existing workflow currently requires programmatically keeping track of EVERY parameter used in the tree and updating them all manually, undermining a lot of the convenience and simplicity of a node-driven animation system.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

expression_node

If this enhancement will not be used often, can it be worked around with a few lines of script?

The AnimationTree is currently only hardcoded to deal with animation poses and does not support any ability to deal with variant types/feeding values into parameters. Engine modifications will be nessecary.

Is there a reason why this should be core and not an add-on in the asset library?

Functionality required to implement this workflow needs modifications to the AnimationTree and its associated editors.

David-Ochoa commented 5 months ago

I think Flax Engine has the right idea about the animation trees (they call it anim graph), they have PARAMETERS and then with the GETPARAMETER node they get the value you set in editor/code. But implementing something like that may need a full rewrite of the animation tree. Anim Graph Parameters

BUT you can do something similar with a simple script in Godot, continuing with the way advance expression were implemented.

Let's say you already have a script with some exported variables for the advance expressions, then we do:

a) add another export variable to be used with a blend tree, let's say CURRENT_ACTION. b) In the script when you modify/read the exported variable you change/read the value from the blend tree c) You need to inherit your script from TOOL to allow the changes to be visible in the editor

And then you can change those values from the editor and test your Animation Tree without running your project.

I made a video about this on Youtube, it's in C# but can be easily translated to GDScript: Character Setup

Illauriel commented 4 months ago

Very nice proposal! ❤️ For now I'm sticking with StateMachines precisely because it has Advance Expressions, but Trees are potentially more versatile.

BUT you can do something similar with a simple script in Godot, continuing with the way advance expression were implemented.

Well, yes, but only with StateMachines, and this proposal is about getting AnimationTree on par with SM's expression system. It's actually very powerful and saved me a ton of headache.

I made a video about this on Youtube, it's in C# but can be easily translated to GDScript: Character Setup

I'm currently doing something similar with SMs and Advance Expressions, but instead of having a bunch of separate bool flags I have two methods: is_state_active(str) and is_stance_active(str) :)

PS: Thanks a lot for the advice with matching XFade to parent, now I know why my char is T-posing in some cases x))

David-Ochoa commented 4 months ago

PS: Thanks a lot for the advice with matching XFade to parent, now I know why my char is T-posing in some cases x))

I'm glad it helped, I had a lot of troubles with this.

Well, yes, but only with StateMachines, and this proposal is about getting AnimationTree on par with SM's expression system. It's actually very powerful and saved me a ton of headache.

I don't know what you mean this works only with StateMachines, as you can see in the video I'm doing it with a Transition Node and a BelndSpace1D, I'm not sure if I'm missing something