Godot Version
4.6
Question
I ran into an issue while working with some custom classes. Here is the code for PlayerDetectingArea, a class i wrote for keeping track of players inside of an Area2D:
extends Area2D
class_name PlayerDetectingArea
signal player_entered(plr: PlayerController)
signal player_exited(plr: PlayerController)
@export var stack = []
@rpc("any_peer", "call_local", "reliable")
func append_to_stack(obj):
stack.append(obj)
@rpc("any_peer", "call_local", "reliable")
func remove_from_stack(obj):
stack.remove_at(stack.find(obj))
func _on_body_entered(body: Node2D):
if !multiplayer.is_server(): return
if not body is PlayerController: return
if body in stack: return
append_to_stack.rpc(body)
General.emit_signal_to_all_peers(player_entered, [body])
func _on_body_exited(body: Node2D):
if !multiplayer.is_server(): return
if not body is PlayerController: return
if not body in stack: return
remove_from_stack.rpc(body)
General.emit_signal_to_all_peers(player_exited, [body])
func _ready():
if !multiplayer.is_server(): return
body_entered.connect(_on_body_entered)
body_exited.connect(_on_body_exited)
for body in get_overlapping_bodies():
_on_body_entered(body)
basically, it keeps track of players inside it in the stack variable and fires custom signals, player_entered and player_exited when a player joins or leaves the stack.
Now, i have a class that inherits from this:
extends PlayerDetectingArea
class_name StealthArea
func _ready():
super._ready()
if !multiplayer.is_server(): return
player_entered.connect(_on_plr_entered)
player_exited.connect(_on_plr_exited)
for plr in stack:
_on_plr_entered(plr)
func _on_plr_entered(plr: PlayerController):
if !multiplayer.is_server(): return
plr.change_stealth.rpc(true)
func _on_plr_exited(plr: PlayerController):
if !multiplayer.is_server(): return
plr.change_stealth.rpc(false)
the problem i have is that with this class specifically, when i instantiate a stealth area, the events player_entered and player_exited never fire. I’ve already checked that the stealth area’s CollisionShape2D is not disabled and monitoring and all that jazz, and also other scripts that inherit from PlayerDetectingArea work just fine. I’m really confused as to why these events won’t fire
Just for clarity’s sake, here’s the stealth area’s scene tree:

and this is what it looks like in the editor:
