Hi, this is something I didnt understand yet on godot , supposing we have a scene with root="Node3D" with an single child "bugNode3D", with the following scripts :

root node "Node3D"

extends Node3D
var test:Node3D
func _ready():
	test=Node3D.new()
	add_child(test)

The chield "bugNode3D" script :

extends Node3D
@onready var parentNode = $".."
func _ready():
	var n: Node3D = parentNode.test
	prints(n) # prints null, dosent matter if I change priority, nothing seems to works

It seems root will allways loads last, dosent matter if priority is changed, dosent matter if I use @ready or anything, how can I prevent null from happen on this case ?

  • I fixed it by using _enter_tree insteed of _ready... I still miss something like _allReady() thought.

    extends Node3D
    var test:Node3D
    func _enter_tree():
    #func _ready():
    	test=Node3D.new()
    	add_child(test)

Set the variables from the parent node:

In the "bugNode3D" script (at the top, before any functions):

var parentNode
var n

In the parent script's _ready() function:

$bugNode3D.parentNode = self # This variable may not be needed.
$bugNode3D.n = test

    DaveTheCoder That would fix the particular problem of the example, but not the cause. In my case for example, the parent node is a map that loads lots of procedural objects, that are needed on child nodes. I wonder if this is not a bug because @onready should wait for the ready function to complete.
    The odd thing is that if you call in the bugnode3d something like Node3D.is_node_ready() its return true, even tough its not...

      A parent node is not "ready" until its children are "ready". That's how the engine works.

      IceBergyn the parent node is a map that loads lots of procedural objects, that are needed on child nodes

      Maybe you could do the loading in an autoload. Autoloads are placed at the top of the scene tree, before other nodes, and their data is available globally.

      I fixed it by using _enter_tree insteed of _ready... I still miss something like _allReady() thought.

      extends Node3D
      var test:Node3D
      func _enter_tree():
      #func _ready():
      	test=Node3D.new()
      	add_child(test)