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():

func _ready():

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()

func _ready():
asked Sep 13, 2017 in Engine by friendlyapprentice (22 points)
edited Sep 15, 2017 by friendlyapprentice

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.

answered Sep 13, 2017 by volzhs (7,409 points)
selected Sep 15, 2017 by friendlyapprentice
+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?

answered Sep 13, 2017 by kidscancode (4,536 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.