Cannot access node using "$" or "get_node"

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

Hi! I want to access a node using code. The scene root node (in this case a Control node) has a script, called, and I want to access some direct children nodes using the $ operator, in this case:

extends Control
onready var texture_button = $LeftButton

func _process(delta):
    if texture_button.is_pressed():

This worked fine when I ran the code in, but I need to run it in instead. I do not see where I am going wrong, but the code basically says that $LeftButton does not exist.

Where is my problem?

:bust_in_silhouette: Reply From: Squash

You said it is a direct child of the node, but just in case: If the script is on Node1 and you're trying to path to Node3, you need to put Node2 in the path too. it would look like:$Node2/Node3

If that isn’t the problem, I don’t know what else could be causing that.

Sorry, I forgot to add a screenshot.

No, this isn’t the case. The structure is:

- Control FS (root)
      - LeftButton
      - RightButton

Cloud Worm | 2020-12-28 09:27

im actually having the same proplem. did you find a solution to your problem ?

devcutter | 2023-04-03 21:30