0 votes

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... :P

could you please help me ?

asked Jun 11 in Engine by nonomiyo (186 points)

1 Answer

0 votes
Best answer

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).

2) 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).

answered Jun 11 by Zylann (14,838 points)
selected Jun 11 by nonomiyo
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.