Welcome to the forums @rylan!
What does the scene tree you are using look like and what node is the script attached to?
As @fire7side said, the issue is that the code cannot find the node relative to the scene tree. So for example, if you have the following scene tree:
If your script is attached to Main
in the above example scene tree, then you can get the node using:
// Local NodePath (starts from the current node and travels down)
var playerInstance = GetNode<Player>("Objects/Player");
// Global NodePath (starts from the root of the scene and travels down)
// var playerInstance = GetNode<Player>("/root/Main/Objects/Player");
The GetNode function takes a NodePath, which tells the function how to get the node. The NodePath can go from either the current node (local) or the root (global) and travel down the scene tree until it gets to the node you specify.
If possible, I would recommend using local NodePaths (Objects/Player
), as they tend to be a bit more flexible. Because it is relative, as long as the children node are what you expect, the code should always work. That said, sometimes a global NodePath is the easiest way to get a node. For example, if you are trying to get "Player" from "Other" in the example scene tree, a global NodePath (/root/Main/Objects/Player
) is probably the best way to get the node.
(Side note: You can also use FindNode("Player")
, which will look through all the children until it finds a node with the same name as the first argument. However, this is costly for performance compared to using GetNode
).