How do you set a variable in a scene instance before _ready?

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

I have a scene with a 2D Node as root and attached GDscript. I want to set the value of a variable in an instance of the scene that tells the scene which animation to play. I need the variable to be set before the scene _ready event is encountered. I created an export variable in the script and set its value in the scene editor for an instanced child scene. However the value I set is not seen in the _ready function. Is what I am trying possible?

Thanks,

-brian

:bust_in_silhouette: Reply From: Sween123

Yes.
The function _ready() will only be called when the scene enters your game world.
Using an export var is fine, it can work. When the game start, the value for the exported variable will be the value you assigned in the Godot Editor. (You won’s see the change of value in the script when you are editing because the script is what contains the code for scenes! But you can see it in the inspector)
Or if you are instancing through code, before you add the child (add_child(NODE)), using TARGET.set(VARIABLE_NAME, VALUE) to assign a value for its variable.