Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jarlowrey |
This variable is set to false twice in a row, which causes the signal error to appear in-game.
func set_kill_on_viewport_exit(val):
kill_on_exit = val
if is_inside_tree():
if kill_on_exit:
$VisibilityNotifier.connect("screen_exited",self,"kill")
else:
$VisibilityNotifier.disconnect("screen_exited",self,"kill")
This dirtier code fixes the error by ensuring the signal is only disconnected once. Is there a better way of preventing the error?
var _vis_signal_is_connected = false
func set_kill_on_viewport_exit(val):
kill_on_exit = val
if is_inside_tree():
if kill_on_exit:
$VisibilityNotifier.connect("screen_exited",self,"kill")
_vis_signal_is_connected = true
elif _vis_signal_is_connected:
$VisibilityNotifier.disconnect("screen_exited",self,"kill")
_vis_signal_is_connected = false