How to determine a VisibilityNotifier2D is out of screen by the _screen_exited signal?

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

When the VisibilityNotifier2D is removed from parent(not by queue_free), it also emits _screen_exited, How can I determine whether it is emitted by move out of screen or removed from the scene?

:bust_in_silhouette: Reply From: volzhs

I think you can determine that with is_inside_tree() method.

func _on_screen_exited():
    if is_inside_tree():
        # it's out of screen
    else:
        # it's removed from tree

Have you tried this in 3.1?
After call get_parent().remove_child(self).
the _on_screen_exited will be called and the is_inside_tree() still return true.

alexzheng | 2019-05-04 06:54

i was just guessing.
there could be workaround but it looks not clean.

func on_screen_exited():
	yield(get_tree(), "idle_frame")
	if is_inside_tree():
		print("node is out of screen")
	else:
		print("it's removed from tree")

tested it and worked as expected but hm…

volzhs | 2019-05-04 14:07

yes,I knew this workaround.
I used another method call_deferred also works.

As you said, it looks not clean, I’m looking for a straightforward way.

alexzheng | 2019-05-05 03:13