How can I use variables in an animation?

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

I have an object that will “wiggle” once on collision with others by slightly increasing and decreasing it’s sprite’s scale. I managed to create this effect in a simple AnimationPlayer node animation by setting the scale to (1, 1), (0.9, 0.9), (1.1, 1,1.) and back to (1, 1). The problem is that the object uses a custom ‘size’ variable to set the scale, so whenever I want it to wiggle it resets the scale back to 1. Is it possible to use this variable in the AnimationPlayer node to make this effect relative to the current object scale?

:bust_in_silhouette: Reply From: Inces

add track : property track : script_variables : size.

Add track is this PLUS icon in top left corner of animation player menu.

Or you can export your size variable and than You will see it in editor, so You can keyframe it

Yeah I eventually figured out I could use exported properties in the AnimationPlayer and made a relative_scale variable with a setter function in which I set the scale by multiplying the base size with the relative_scale.

Thanks for the support anyways.

VGenesis | 2021-10-09 10:59

But all vars doesnt shows up this way, only the exported does in the script variables. Why?

Gazi Safin | 2023-04-24 06:09

Because this is what exporting does : it exposes variable in all editor menus. Built-in properties are exported by default

Inces | 2023-04-24 14:25