Why are `onready` variables referenced in another node `null` in `_ready()`?

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

Why are onready variables referenced in another node null in _ready()?

For example:

in my game node:

onready var player = $Player

in my another node:

onready var game = $"/root/Game"

func _ready():
	print(game.player) # null

If your other node is in the Game scene, you can actually access the Game node via the owner property:

func _ready():

Dlean Jeans | 2019-06-05 16:50

:bust_in_silhouette: Reply From: Dlean Jeans

This is because _ready in your other node is called before your Game node.
This is what I find myself doing in my Game node:

var player

func _enter_tree():
    player = $Player