Invalid get index 'global_position' (on base: 'null instance')
- Edited
If line 30 contains the expression player.global_position, then the problem is that player is not a valid reference.
Add this:
func _ready() -> void:
print_debug("_ready, player=", player)
Add this at the beginning of func on_timer_timeout():
print_debug("on_timer_timeout, player=", player)
Add this at the beginning of func get_random_position():
print_debug("get_random_position, player=", player)
What is the output?
DaveTheCoder What is the output?
This may not even be executed because someone is likely calling get_random_position()
prior to node being ready. Likely a _ready()
of a sibling that initializes first. Or there is some mess up with unintentional signal connections. Hard to tell without seeing the scene structure.
- Edited
That's true, but you have to start somewhere.
I edited my post to add some more print's to deal with those cases.
DaveTheCoder nothing changes, the same error is still happening
- Edited
Pomelo No lines highlighted
Are you sure? Because every time an exception is thrown, the execution is stopped and the stop line is highlighted by a yellow arrow. The top entry in stack frames window will also specify at which line in which script the execution stopped. Double clicking on that will bring you to that line in the code editor.
Ok, I just fixed it
I had to add a
func _ready():
player = get_node("/root/Main/Player")
And it started working