Scene1 script to "set_hidden" Scene2 ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By friendlyapprentice
:warning: Old Version Published before Godot 3 was released.

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")
:bust_in_silhouette: Reply From: kidscancode

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?

:bust_in_silhouette: Reply From: volzhs

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.