how to get_tree from other scene?

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

i want to get node from Main.scene to script in block.scene


the block.scene not in the main.scene beacuse block.scene will automatically show up

how to get_tree sprite in other scene ?
here is the screenshot

enter image description here

:bust_in_silhouette: Reply From: AlexTheRegent

This is bad concept design, because your components will be tightly coupled. Instead, you can pass reference to Main node to your when you instance this node, for example:

var main 

var block = Block.instance()
block.main = self

so instead of get_tree().get_parent() you will simply write main.

Or you can expose it as member of Singleton class (

var main

func _init():
  Provider.main = self

then get_tree().get_parent() can be written as Provider.main.

i see… thank you for the answer… i’ll try it then

okkyhw | 2021-07-23 10:13