Is there any way to reuse an animation in the AnimationPlayer

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

For example I have a bunch of RichTextLabel, and I want to use the same animation (just change opacity to fade in) for all of them.

Which is the best way to achieve this using the AnimationPlayer?

:bust_in_silhouette: Reply From: sleepy

click on the copy animation button, then rename it to what you want. You can then change the animation as needed.

If I’m not wrong in that case I need to create as many animations as text (or other node) I have in my scene. It seems a bit inefficient. I would like to simply add it as a function that play animation get_node("whatevernode").play("whateveranimation") because I will play the same animation (change the same property for every element). I can create instances of text with the animation included, but I would like to know if it is possible just using animation tracks with already created nodes.

al.glez | 2016-05-25 19:18

:bust_in_silhouette: Reply From: al.glez

OK, I answer myself

Actually you can just change the path. So you can set a path to a textlabel and change and play the animation as needed. I didn’t test it, but It will be something like this.

get_node("animationnode").get_animation("whateveranimation").track_set_path(0, "pathtonode:properties"))
:bust_in_silhouette: Reply From: rgrams

Just make a scene with your RichTextLabel and an AnimationPlayer and instance that, then they will all have the same functionality.

If you have a bunch of things that will always change together, use a material. By default they will all share the same material instance, so you only have to change it in one place.

Yes I thought about your first approach. The problem is that if I have a bunch of elements and I they have different properties already predefined except the one I want to animate, It will be a bit tedious.

I will look further into the second approach.

al.glez | 2016-05-26 15:26

Hmm, yeah I don’t know your exact situation, but it seems that since you can nest nodes and scenes as much as you want, and put a script on multiple nodes in a scene, it should work. But maybe not.

rgrams | 2016-05-26 16:20

Yes probably my question was too vague. At the moment I’m using track_set_path method I mentioned in my answer and It’s working pretty well.

al.glez | 2016-05-26 16:25

:bust_in_silhouette: Reply From: puppetmaster-

You can save animation as resource and load it in animation player.