What's the cleanest way to handle" duplicate" animations for different sprites?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jeff
:warning: Old Version Published before Godot 3 was released.

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?


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?

Zylann | 2016-11-29 01:50

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


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.

jeff | 2016-11-29 08:14

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

Zylann | 2016-11-29 13:21

:bust_in_silhouette: Reply From: jeff

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.