Project crash when node emit signal

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

Maybe you got this project somewhere for a collaboration or just reference somewhere. Because this looks like an army drill to figure out what’s wrong with your code. Why are you trying something new? I think you’re doing the signal wrong.
Your signal is in Daily. Your button also in the daily. When you push the button menu it’s supposed to emit a signal called return_to_menu. Unless you have a signal in the Menu button script. It doesn’t know what you’re talking about.
Or, simply put. This will work if Daily has a signal. Daily emits the signal. Daily runs the ending script. And, ignores the Menu.

1 Like

Thanks for your suggestion.
I was a bit messed up when describing the problem. It is true that the signal “return_to_menu” is of the node Daily, and what the menu_button does is trying to make the node Daily emit that signal. It really is a mess
I have cleaned up those signals, try another way, and it goes well. For now at least. Looks like I should not mess up with signals too much (they are really so picky)
I’m still a newbie so it takes me many more trial and error to understand this engine.
Again, thanks for your reply

Probably worth converting these connect and emit calls to the 4.x style.

# Maseter_scene: connect using the signal name instead of a string
daily_scene.return_to_menu.connect(open_menu_scene)

# Daily_check: emit using signal name
return_to_menu.emit()
1 Like

Well, that’s how it works. In Daily;

signal return_to_menu

Create the signal.

menu_button.return_to_menu.connect(self._on_menu_pressed.bind())

Connect the signal.

func _on_menu_pressed():

daily_scene.queue_free()

Make the functionals.

func _on_menu_button_pressed():

return_to_menu.emit()

This is all in Godot 4. Granted this is with built in functions in the mix.
Anytime you get stuck. Just call to;

print(return_to_menu.get_connections())

That should really clean up your schedule in between signals.

1 Like