Checks for game stopped by editor

Godot Version

Godot 4.2

Question

This code allows you to check when the game is close by the X button.

func _notification(what):
	if what == NOTIFICATION_WM_CLOSE_REQUEST:
		get_tree().quit() # default behavior

But it didn’t work when the stop button in the editor is clicked.
How do I make it checks for when the game is closed by the editor?

You would need to check for the system singal SIGKILL (aka 9 in linux), but I don’t know that godot provides an easy way to do that. In any case, you shouldn’t be doing that without a very good reason.

I was using OS.execute command to run a python program and I want it to close when the godot game is closed.

Because of the way the kill signal works, there is no guarantee that anything you do from the godot side would run, so the most reliable option would be to pass the PID to the python script, then regularly check if that process still exists.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.