NOTIFICATION_WM_GO_BACK_REQUEST button is triggered for new scene

Godot Version

4.4.1

Question

I have Scene1Scene2Scene3 for android.
Scene2 and Scene3 have function below:

func _notification(what):
	if what == NOTIFICATION_WM_GO_BACK_REQUEST:
		_on_back_scn_btn_pressed()

The problem is when i press back button on Scene3, Scene2’s above method is also triggered which causes Scene3 to go to Scene1 bypassing Scene2 (which is absurd!!) How can i prevent unnecessary trigger? I dont want to create variables just to handle this situation, it seems anti pattern.

If Scene2 is being triggered then it means that the node is in the scene tree. If that’s intended then you’ll need to keep track of the current scene stack in code. If that’s not intended then you’ll need to, at least, remove Scene2 from the scene tree.

No it is not, for my every scene, i use node.free(). I checked remote view and that scene was not in tree. They are major scenes, i load them everytime i use back pressed and free them when i am done.

Are you sure? The only way that that notification can reach a node is that the node is in the scene tree.

Here’s where it gets emitted godot/scene/main/window.cpp at 4d7c448a0a58ff4b14d4a06c4b1bb387b58f4508 · godotengine/godot · GitHub and here is the _propagate_window_notification() implementation godot/scene/main/window.cpp at 4d7c448a0a58ff4b14d4a06c4b1bb387b58f4508 · godotengine/godot · GitHub

1 Like

i opened bug for this in github.