Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | shortcake |
I am currently making a simple tree which looks like this :
MainNode (Parent) → Character (Child)
MainNode can add child or free one from any files such as maps (i.e. terrain.tscn) or events (i.e. event.tscn). All events and maps will be stored in a dictionary for easy usage. The codes would look like this :
func loadNewScene(key):
# load the corresponding tscn file from dictionary
add_child(instanced_scene)
func freeScene(key):
# find the corresponding target node using key
target.queue_free()
func _ready():
# load Mainmenu.tscn
loadNewScene("Mainmenu")
My problem begins when I press start in the Mainmenu.tscn. If I had Mainmenu.tscn as a child (in default), I can always emit a signal for confirming the player press the button to fire a signal to proceed to the next scene, such as :
func _on_Button_pressed():
var target_scene = "Opening Scene"
freeScene(current_scene)
loadNewScene(target_scene)
But since the node isn’t actually in the MainNode (It will be added as a child after _ready() ), I can’t find a way to emit a signal from “Mainmenu.tscn” to MainNode, because initially it’s not in the MainNode’s tree.
Is there a way to make a signal to a different tree? Or is there a alternative solve for this?
[note : This question is also on stackoverflow. I’m posting on both platforms ]