0 votes

I'm trying to access the ID of my player's kinematic body (PlayerBody) by setting it in a global static NodeReference class via the PlayerBody's _Ready function.

A child node of PlayerBody (in the scene) accesses the ID via this following declaration. (This should work like a get-property if I'm not mistaken):

private ulong _playerID => NodeReference.Player.PlayerBody.GetInstanceId();

However the PlayerBody's _Ready method (C# for function basically) is never called before the _Process method of this child node is called, so I get a Nullreference exception thrown. Shouldn't _Ready be called on all nodes on the scene before _Process?

Is there any other way to make sure that all nodes are initialized the way I want before _Process?

in Engine by (18 points)

1 Answer

0 votes

the _ready function is called when all children of the node are initialized. So the ready call is inside out. The process function is called for every ready node. So, if the initialization takes some time other nodes will receive a process before the parent is ready.

Maybe you want to turn off processing on your child nodes until the parent signals its ready state.

by (4,058 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.