Is there a way to know when does an AnimationPlayer's property value is changed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SebSharper

Hi there.
I have a sprite with an AnimationPlayer as a child of it, along with another sprites too. The AnimationPlayer animates the main sprite (parent) but I need it to animate the other sprite nodes too (children). I already have the animations made for the parent sprite, the issue is that I want to use the exact same animations but with the other children sprites. As Godot does not have a copy/paste keyframes in different track feature, I was thinking about setting the children’s frame value the same as the parent sprite’s animated frame value in process() function, but that may produce a bad perfomance, so I was wondering if there is a signal or a way to know when does the frame property in the parent sprite changes value to set it to the children sprites too.

Would it be possible to instance the animation player as a child scene or several children of the original animation player? Something like this:

enter image description here

And start them all at the same time?

MRimmer | 2020-11-13 16:20

So you’re suggesting that I add an AnimationPlayer as a child of the already existing animation player for each of the sprites that I want to animate, just change the target to the corresponding node and the properties should change just like when changing the position of a parent node changes the children’s position too?

SebSharper | 2020-11-13 21:57

:bust_in_silhouette: Reply From: aqsis

I may be wrong, but as far as I can tell, there is no “driven values” mechanism in Godot, like in Blender for example, which is a shame, and would be a very valuable enhancement IMHO.

I’ve tried to emulate this facility in a little example, using scripts and signals. In the attached example, I’ve added a public variable to the parent sprite, “Driver” that I animate instead of animating the scale directly, in the setter for that value, I emit the driven value changed signal. It’s possible then to hook that signal up to whatever you want to be driven by the changes. In this example, I hook it up both internally to the scale, and then hook separately into the child sprite, “Driven”, to alter its scale too. Unfortunately, this means it will be difficult to review the animation as you edit it, as the script on the driver won’t run and you therefore will not see the effect of your animation as you play it.

Hope that helps a little.