+1 vote

Hi! I want to access a node using code. The scene root node (in this case a Control node) has a script, called Control_FS.gd, 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 LeftButton.gd, but I need to run it in Control_FS.gd instead. I do not see where I am going wrong, but the code basically says that $LeftButton does not exist.

Where is my problem?

Godot version 3.2.2.stable.official
in Engine by (13 points)

1 Answer

0 votes

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.

by (19 points)

Sorry, I forgot to add a screenshot.

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

- Control FS (root)
      - LeftButton
      - RightButton
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.