Node not found: "Head" (relative to "/root/Player")

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

the game cant find the “Head” node even though it exists

Code
@onready var eyes = get_node(“Head”)

 

For that to work, your Head node would need to be an immediate child of the node that the above script is attached to. I assume that’s not the case. If that doesn’t help you to solve the issue, post your scene tree structure, and note which node the above script is attached to.

jgodfrey | 2023-06-28 19:31

It is a child of the node with the script. I cant figure out how to upload a picture to this website.

K29 | 2023-06-28 19:55

To post an image…

  • Upload the image to a cloud storage site (Google Drive, DropBox, OneDrive, …)
  • Using the cloud site, get a publicly accessible link to the image
  • Paste that link in your post here

jgodfrey | 2023-06-28 20:02

Hi

will this line help?

@onready var eyes = get_tree().root.find_child("Head", true, false)

GameSchool | 2023-06-28 20:14

It worked thanks!

K29 | 2023-06-28 22:17

Note that find_child() iterates through all descendants of the target node (the root node in the case of the sample code above). Because of that, it’s not very efficient. While that may not matter to you (or may not matter in this case), if you know where the target node is with respect to the script that’s trying to access it, using get_node() is much more efficient.

Also, the fact that find_child() is working but your earlier attempt with get_node() is not working tells me that the relationship between the nodes doesn’t match what you’ve described here…

jgodfrey | 2023-06-28 22:55

codenode2.PNG - Google Drive

K29 | 2023-06-29 14:41