If you're looking to detect when a node is on or off the screen, then you should use VisibilityNotifier instead. Basically it detects when a node is off or on the screen. Just add a VisbilityNotifier as a child of the enemy, connect the VisibilityNotifier's signal, screen_exited()
, with the enemy, and tell the enemy to go to the desired position when the signal is emitted.
In order to get the "desired position", in your case, it's original starting point, then you should create an onready var equal to the enemies position like onready var start_pos = position
. Basically what that does is, as soon as the scene starts, it's current position (also its starting position because the scene just started) is kept in a variable, which you can use later when the screen_exited()
signal is emitted, like
func _on_VisibilityNotifier2D_screen_exited():
position = start_pos