changing a variable's value from Call Function

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

Hello !
Is it possible to change a variable’s value from the animation panel ?

I created a Call Func track, targetted the node with the variable script, then added a key and tried writing this in the ‘name’ section :

myvariable = 1

it didn’t work.
I then tried to put only “myvariable” in the name section, then “1” in the Int Argument section.
but it didn’t work either… :stuck_out_tongue:

could you please help me ?

:bust_in_silhouette: Reply From: Zylann

You have two ways of changing variables from AnimationPlayer:

  1. Adding export in front of that variable.

This will make the variable accessible from the inspector, and that means you will be able to animate it (which regularly sets this variable when the animation is playing).

  1. Making a setter and call it

If you just want to set the variable in a specific point in time, or if you’re not keen on exposing it in the inspector, you can create a function to set it, like:

var myvariable = 42

func set_myvariable(value):
    myvariable = value

Then you will be able to call this function with the wanted value using a Call Func track (write the name of the function, add one argument, set its type to integer, and write the value it should have).