How are the VisibilityNotifier2D node signals supposed to work ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Laurent Tréguier

I am having a little trouble with the VisibilityNotifier2D node.

I have a game that I’m testing in a window, and I’m simply trying to detect when an object is going out of the visible window space. I have first connected the screen_entered and the screen_exited signals, and then the viewport_entered and the viewport_exited signals to a function printing either “enter” or “exit”.
While the *_entered signals are emitted right when the node enters the window, the *_exited signals however are not getting emitted immediately after the node exits the window. As long as it’s not “far enough”, so to speak, outside the window, they don’t seem to be emitted.

So if the node just stops there and doesn’t move, then it can be entirely outside of the window but never emit the *_exited signals.

Is this a bug ? Or am I doing something wrong ?
I am using Godot 3.0.2 stable from Steam if that’s of any relevance.

:bust_in_silhouette: Reply From: fkul

That’s the way it’s designed. It was a choice between speed and accuracy, and they chose speed.

This makes sense, since most people probably use it to have nodes remove themselves without having to know the window or screen boundaries, especially in shooter-style games with a lot of objects onscreen at once.

If you want to be more precise, you’ll probably want to add Area2Ds or similar colliders to your window boundaries.