Node tree:
Scene
|-----Player
|-----Sprite
|-----Enemy
|-----Sprite
The problem:
In Player, I have a variable playerX that gets updated every frame (it's equal to self.position.x).
In Enemy, I have a variable targetX whose value I want to be equal to the value of playerX in Player (in every frame).
In Enemy, the code for targetX (in process(delta):) looks like this:
targetX = get_node("root/Scene/Player").playerX
When I run the program, I get an error Invalid get index 'playerX' (on base: 'null instance').
I read a lot about this problem but the solutions didn't help me at all. The proposed solutions were:
-check if the node path is correct -> it is correct
-learn the order in which the nodes get executed in the tree
-check which node is set as your main scene
-put the variable in the Scene node