0 votes

Both scene1 and scene2 are inside a main scene3.
Why won't the "Button" node from scene1 script hide (interact with) scene2?

-scene3 node
--scene1 node(contains "Button")
--scene2 node(contains "Node2d/Sprite")

extends Panel

func _on_button_pressed():
    get_node("Sprite").set_hidden(!get_node("Sprite").is_hidden())
    get_tree().get_root().get_node("scene2").set_hidden(!get_node("scene2").is_hidden())

func _ready():
    get_node("Button").connect("pressed",self,"_on_button_pressed")

Edit: Okay I've since realized that the scenes weren't instanced properly. The following worked:

-scene3 main node
--scene1 node
---scene2 node

extends Panel

var block

func _on_button_pressed():
    block = load("res://scene2node.tscn").instance()
    get_node("Sprite").set_hidden(!get_node("Sprite").is_hidden())
    get_node("scene2").set_hidden(!get_node("scene2").is_hidden())

func _ready():
    get_node("Button").connect("pressed",self,"_on_button_pressed")
in Engine by (22 points)
edited by

2 Answers

+1 vote
Best answer

where is the "block" node?
you don't have to start with get_tree()

you can get a reference in various ways.
one of way is using get_parent()
if "block" node is located at parent of your current Panel,
you can get it with get_parent().get_node("block")

or just simply do get_node("../block") with relative path.

by (9,662 points)
selected by
+1 vote

At a glance, it could be because you're using get_tree().get_root().get_node("block") in one case and get_node("block") in another. Those aren't the same path.

Other than that, you should probably provide more information. What does your node tree look like?

by (19,695 points)
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.