Nodes arent being found?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Chickentendie007

It shows an error that is it trying to get the node but then it failing to find the node.

E 0:00:00.713 get_node: (Node not found: “Head/Camera/gun_pick_Up” (relative to “/root/Player”).)
E 0:00:00.713 get_node: (Node not found: “Head” (relative to “/root/Player”).)
E 0:00:00.713 get_node: (Node not found: “Timer” (relative to “/root/Player”).)
E 0:00:00.713 get_node: (Node not found: “Head/Camera/Head_Bob” (relative to
onready var gun_pick_up = $Head/Camera/gun_pick_Up
onready var head = $Head
onready var timer = $Timer
onready var anim_play = $Head/Camera/Head_Bob

cant figure out how to input images without it being only on my laptop

That is a url to a local file, it can’t be viewed.

zhyrin | 2023-03-23 11:32

You can upload images to an image sharing website like imgur and link to the uploaded image.

zhyrin | 2023-03-23 13:26

With only the variable declarations and errors it’s hard to say what causes the problem. Having a look at your scene tree and seeing to which node this script is attached would help.
My two guesses are:
a) the nodes you try to reference don’t exist
b) you misspelled the nodepaths

zhyrin | 2023-03-23 13:30

:bust_in_silhouette: Reply From: Lopy

Your node paths are likely wrong. You can check that they match the scene tree in case you spot the issue. If you don’t notice anything, try to call print_tree(), or print_tree_pretty(), in your _ready. This will show you the children of your Node while the game is running.

To better see what is happening, start your game, then focus the Editor without closing the game, and just above the tree view on your left, select “Remote”. This will show you the tree of your game as it is running.

Common reasons why $/get_node() would fail:

  • A Node was removed in code using queue_free or remove_child.
  • Names/paths do not exactly match.
  • Paths used to match, but Nodes where moved around or renamed.
  • The script was put on another Node by accident, with ill-named children.
  • A Node was renamed automatically to guaranty the uniqueness of names among siblings.
  • Called inside an _init() instead of a _ready().

To avoid having to keep node paths up to date, you can use find_node, which is “slow”, or find_parent and have the children register themselves (find_parent("player").camera = self). Godot 4 adds the % syntax to simplify addressing Nodes.