Is there a way to prevent VisibilityNotifier2D from emitting 'screen_exited' signal when I change the scene?

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

So basically say for a game like breakout, I have visibility notifier connected to the ball and I emit 'game_over' signal when it exits screen. Problem is, in my pause menu, there’s a ‘restart level’ button which basically just reloads the current scene after calling get_tree().paused = false which in turn ALSO calls the ball’s visibilityNotifier’s screen_exited signal causing game_over to be emitted even when the person just restarted.

TLDR : changing scenes is calling visiblityNotifier2D to emit signals. How to stop that case?

:bust_in_silhouette: Reply From: Adam_S

Disconnect the screen_exited signal before changing the scene.

$VisibilityNotifier2D.disconnect("signal_name", target_node, "method_name")

Yeah I was hoping there was a better way than getting a list of all VisibilityNotifier2D and disconnecting them before every scene change.
The other thing beside this which I tried which worked better I suppose was to use a boolean inside of VisibilityNotifier2D for further handling which would allow it to get called as much as it’d like and not hinder the other processes.

idkaryan | 2019-09-27 02:32