0 votes

Hi, everyone.
I have a node Road which has some Spatial nodes.
The main scene Game has Road as a child. Game calls $Road.advance() method in _ready. As a result I have an error Attempt to call function 'advance in base 'null instance' on a null instance..
It, as I think, means that Road is not "ready" or it is an engine bug (0_o).
I've putted print(get_children()) in Game._ready method and had [].
I always thought that method _ready in the parent is called only after all children called their _ready. This is really surprising for me.
Have anyone stucked with a problem like this one? It might be something common.

I tried to put print("Road is ready") to Road._ready and it wasn't ever printed.

I cannot add images now, sorry, but the hierarchy is really simple -- just a child node in parent, and it is never "ready" ;(


func _ready(): $Road.advance() # ERROR: Road is nil


func _ready():
print(”Road is ready") # Never printed

func advance():
# Some logic

I'm absolutely sure, that, at least in the editor, the Road is a child of the Game. But, maybe, something out of user view is wrong, maybe inside .tscn files. Anyway, I've tried recreating Road and Game scenes from scratch -- does not help. Now have no idea why this may happen.

Godot version 3.4.4.stable
in Engine by (20 points)
edited by

Have you tried using Play Scene (F6 by default)? Does the problem repeat?

Ohhh... The problem is that Game is present in AutoLoad, i.e. it is a singleton.
Thanks for the idea about scenes.

1 Answer

0 votes

The problem was in that Game is singleton (added to AutoLoad), thus, as script, it was ready, but not as a scene.

by (20 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.