Godot Version
4.2
Question
So I am using a Master scene to monitor scenes, add_child and queue_free plenty of them from time to time. There are so far 3 of them: Main_menu, Office and Daily_check, within which there is a button to transit to another scene. The buttons’ “pressed” signal is connect to a function in the Master_scene’s script.
Below is a part of the Master_scene’s script:
var menu_scene = load(“res://Menu asset/Main_menu.tscn”).instantiate()
var office_scene = load(“res://Office asset/Office.tscn”).instantiate()
var daily_scene = load(“res://General asset/daily_check.tscn”).instantiate()
[…]
func _on_menu_scene_closed():
menu_scene.call_deferred(“queue_free”)
add_child(office_scene)
office_scene.connect(“player_left”,_office_left)func _office_left():
add_child(daily_scene)
office_scene.call_deferred(“queue_free”)
daily_scene.connect(“return_to_menu”,open_menu_scene)func open_menu_scene():
add_child(menu_scene)
menu_scene.connect(“menu_closed”,_on_menu_scene_closed)
daily_scene.queue_free()
Everything works well until this Daily_scene, with a button called “Main menu”, which emit a signal called “return_to_menu”, is pressed.
Below is a part of the script that is attached to the Daily_check scene/node:
@onready var menu_button = $Control/Main_menu
signal return_to_menu
func _ready():
menu_button.connect(“pressed”,_on_menu_button_pressed)
[…]
func _on_menu_button_pressed():
emit_signal(“return_to_menu”)
During the test run, the project just shut down without any error reported.
I have played around to identify the origin of the problem and come to the conclusion that it comes from the emit_signal function in the Daily_check scene/node’s script. Everything stop just right there, the signal “return_to_menu” is never emitted
I don’t know if this is a bug or I may have messed up somewhere. The same method just works fine for other scene’s transition.
Thanks in advance for any reply