Skip to content
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

AnimationBlendTree performance issue #65199

Closed
TokageItLab opened this issue Sep 1, 2022 · 3 comments · Fixed by #68593
Closed

AnimationBlendTree performance issue #65199

TokageItLab opened this issue Sep 1, 2022 · 3 comments · Fixed by #68593

Comments

@TokageItLab
Copy link
Member

TokageItLab commented Sep 1, 2022

Originally posted by @JoanPotatoes2021 in #53752 (comment)

I am facing breaking perfomance loss if I use physics in process_callback of animation tree, which I wanted because I wanted to have a constant root_motion velocity despite the fps, which points to this issue.

However I didn't wanted to spam another issue because it might be related to alpha perfomance? I didn't saw anything about optmizing animation trees or perfomance issues related to animations though, here's a gif showing my problem,

AnimationTree_SeverePerfomanceLoss_onProcessCallback_Physics -note that gif was rendered to 20 fps

I might not be using animation trees correctly, but this seems how it was supposed to work? Here's how is structured, it was designed for a third person shooter. I saw this type of animation tree being done for other projects, is it that costly to blend multiple animations? I am a little worried to be honest,

2

Why I am getting so much perfomance loss setting the process callback to physics? I would expect just like Calinou pointed out, to limit the update rate of the animations,

That gif was on an complete empty project, my skeleton have 107 bones, the tree is very complex and I have a lot of animations but by no means should it drop so low, something's going on. On my full project it drops from 240 fps to ~5-20 fps with just 5 characters with meshs and this very same animation tree and skeleton.

REF
v4.0.alpha15.official [432b25d]
Windows 10, Nvidia Geforce GTX 1050 TI, Vulkan

@JoanPotatoes2021
Copy link

Fire, I am uploading a test project, all the animations and the test model are done by me, so they are royalty free for Godot, plus if anyone buys my game in the future the game assets are easily exctractable so I am not worried about them, and honestly mixamo has better animations than me 🌜 ,

Running this test project I get to ~5 fps, the characters were duplicated using Ctrl+D in the editor and are saved as a separate scene "Sample_Character", this is the same way I work on my WIP third person project I mentioned previously, I am running a script to randomize oneshots of the animation tree to give more chaos to the tests, don't know if this helps the optmizations tests or not,

AnimTree_PerfomanceTest.zip

AnimationTree_perfTest

In my game I plan to have 20 to 30 characters at the same time, mind you not all of them would be human, which might be the most expensible characters in the game, more if possible would be also great, so having this perfomance with only 5-6, I will need to explore alternatives to improve it.

My current workflow for this project is to have the rig separated from the characters, this is done exporting a animation rig from blender, with all it's animations in the NLA, and a linked duplicated rig with no animations in the NLA used to hold the skinning information for any meshes, this way in Godot I import the .gltf mesh and change the skeleton to the one that has all animations. This allows me to group assets into separate .gltf files, which helps managing assets from blender,

TokageItLab, the animation_tree node is duplicated, but the tree_root is saved as a resource .tres, I tried to create a animation_tree node in a autoload and pass to the actors but couldn't resolve assigning the animation player in the actors, it failed silently. Now I am interested in what you mentioned with transfer only poses,

One of the optmizations I plan to work on is to reduce the amount of oneshots I have using transition nodes to group them, this in theory should reduce the amount of inactive one shots mixed in the tree, and maybe I can work something out with the blend nodes as well,

animation_tree_grouping

Another idea I tried was to edit the tree_root nodes itself, reusing the same structure, swapping animations using gdscript, but this requires each tree_root to be unique or changing one tree_root node all character using that tree_root would also change that animation node, so in theory this can also work with a specialized small tree unique for the player, if the player needs way more animations than npcs,

@TokageItLab
Copy link
Member Author

TokageItLab commented Sep 1, 2022

For animation, we already have the following three plans for optimization:

  • Multi-threaded blend animation
  • Reduced calculation when blend amount is 01
  • Improved pose update algorithm in Skeleton3D2

Footnotes

  1. The problem with doing nothing when the Blend amount is 0 is that the tracks with 0 amount are not iterated and the blended values is not reset to the init_value correctly. There are two solutions to this.
    (1) When the Blend amount is 0, process only one frame, after that, check the flags and do not process any more
    (2) Iterate all tracks and set blended values to init_value before the blending process
    The former needs to be managed on each Node, and the architectural design becomes more complicated. So probably the latter is a smarter solution that can be adapted generically to any cases.

  2. The Skeleton now has a dirty flag for each bone by IK implementation, but the dirty notification is given for the whole Skeleton each time, and then iterated all bones. This method could be optimized a bit more by the queue or someway.
    Apart from that, access to VisualServer is a bottleneck, so skin updates should be done only once at the end of each frame.

@JoanPotatoes2021
Copy link

So I re-worked the animation tree to a new system, project file below, using fewer nodes whenever possible to achieve the same result as my previous prototype, here's how the second prototype animation tree looks:

AnimationTree_PerfomanceTest_Transitions

This new system looses a lot of blending which I had in my previous test, but it's easier to work with, I thought this system would improve the perfomance because transitions nodes should be easier to optmize, seems it's not the case, running the new prototype it behaved identical to the other, about ~5-6 fps,

AnimTree_PerfomanceTest_Transition.zip

AnimationTree_PerfomanceTest_Transitions_02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants