#why am i gettin this?,,invalid get index 'global_position'(on base: 'null instance)
12 messages · Page 1 of 1 (latest)
get_node can only be used when the node is present in the tree
so you need to pass the reference in a different way
you have to either use an auto-loaded script to store global variables (like player, and then your player can set itself to it)
or when you spawn the mob you pass the reference
preload will not help either because that is the Resource, not the node. It does not exist in the tree.
how do I make an auto loaded script?
you just create a script like any other, but you set it up here
that will be added as a node as soon as you start the game and can be accessed from anywhere
so let's say you called it Globals and add a variable called player
in your player script you can do
func _ready():
Globals.player = self
then you can grab the player from anywhere with Globals.player