No queue_free after focus_in

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pferft

Hi everyone,

there’s a button in my mobile app with which I can free all kinds of currently running instanced scenes, in the way of

if get_node_or_null("SomeScene"):

This works just fine.

However, it appears that if I focus_out and _in again

func _notification(onscreen):
	if onscreen == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
	if onscreen == MainLoop.NOTIFICATION_WM_FOCUS_IN:

the queue_free by pressing the button won’t work anymore, leaving the instanced scenes running.

Maybe anyone had some similar issue with focussing out and in and could give me a hint?

There’s one thing that could be connected to the problem (but I’m not sure – I think it shouldn’t matter…): most of the instanced scenes queue_free themselves from within. Some don’t queue_free but keep looping a function like

func _on_Timer_timeout():
	yield($AnimationPlayer, "animation_finished")

Is it possible that such an instance can’t be queue_freed with get_node_or_null?

There may be a small problem with the Timer functions. Are the corresponding Timer nodes set to one-shot?

Ertain | 2022-03-14 23:30

Yes they are.
In this case the AnimationPlayer actually has a line $AnimationPlayer.advance(1.1) attached, so the one-shot and the looping is crucial (it’s impossible to adjust the timer to have the animation repeat without interruption).

I have the feeling that the focussing-out/in causes trouble somehow, as if the node can’t be found anymore…

pferft | 2022-03-14 23:39