Global.Player was not initialized. Invalid get index 'position' (on base: 'Nil') in PlayerDetection script

I had a problem with variable Player being null after i had changed
onready var Player = get_node("/root/Level1/Player")
to:
onready var Player = Global.Player

I compared my scripts files to instructor’s and they were the same.
The problem was caused by the wrong order of nodes. The Player variable was not initialized because I had placed the Player node after the Guards node.
The keyword ‘onready’ was a little bit misleading.

Good point. It’s true that nodes are initialised in the order they appear in the scene tree, so getting the reference to the player before it had entered the tree would cause the value to be null.

Privacy & Terms