0 votes

For some context, my game features a number of units that all share a number of identical animations in terms of logic. One animation, for example, is the "damaged" animation, where the unit will flicker between two frames. Really simple, identical logic but involves different sprites for each unit.

I know for this simple case I can just reuse a function to play an animation by name in the different AnimatedSprites, but the problem is when I want to reuse a more complex animation, which would have to be created in the AnimationPlayer.

I tried saving an animation in the AnimationPlayer and reusing it among the different unit nodes. It worked for something simple like manipulating the opacity of the parent node, but it didn't work for when I tried to reuse an animation for jumping between 0 and 1 frames of the respective AnimatedSprite, even though the animation names, node names, and frame counts were all the same.

So this really a two-parter question: how exactly does saving and loading animations work when it involves different nodes with different resources, and if that's not the way to go about this, then what's the cleanest way of solving this problem? Is there a programmatic way of doing this?

Thanks!

in Engine by (58 points)
edited by

If your animation didn't worked for two same scenes with the same structure, there must be a problem somewhere, something is probably still different.
Do you have an example project to show this?

Here's a demo. Hopefully I'm not missing something obvious.

https://github.com/jeff-s-zhou/animation-player-test

EDIT: Agh. So I figured it out. It turns out that since my AnimationPlayer animation was using a different AnimatedSprite animation than the default, in order to get the the reused AnimationPlayer animation working, I had to manually set the AnimatedSprite animation of the new Scene to the non default as well. If that makes any sense haha.

I guess the AnimationPlayer's use of keyframes is still unintuitive to me for what exactly it can do magically and what it can't.

Thanks for pointing me on the right track by suggesting that I was experiencing incorrect behavior.

Yeah, animations can animate a lot of stuff, but in return, re-using them requires their environment to match exactly.

1 Answer

+2 votes

The problem was that I also had to change the AnimatedSprite's Animation as its own track within the reused AnimationPlayer animation in order for it to correctly switch to the non-default animation.

by (58 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.