Godot Version
4.2.1 stable on macOS
Question
Hi,
I am new to godot.
I have two instanced scenes who are siblings, children of same “Node”.
One of those scenes is has @export var which is trying to use another scene.
However when I try to use this exported variable in _ready(): function it is “nil”
I tried to test if maybe this is due to the fact this is custom scene/it is not ready or something. But when I tried to do a simple @export variable that is a string, it will also come up as Nil.
Is the thing I am trying to do even viable? Maybe I should not use @export variables in _ready? I could not find anything in documentation regarding this.
Thank you for advance for any suggestions. Let me know if any more information could help with this
The only way I can see this happening (judging by the image alone) is instead of running the node/scene you are creating a PlayerIdleState
object in code via new()
.
Is there something like this in your code somewhere?
var player_idle_state = PlayerIdleState.new()
PS: the string test
isn’t coming up <nil>, it is coming up “” (empty). velocity_component
is what is coming up as nil.
1 Like
thank you for the reply. I was able to solve it.
So I am also exporting this scene in parent node “StateMachine” (to set this state as default one). And it is firing also there.
After printing in _ready function of PlayerIdleState I have noticed it is firing two times. First time it won’t have the @export variables loaded yet. Second time it is fine.
So I just added “if” statement in _ready to avoid the error and it is working fine now