How to know when a player disconnects?
How can clients know when other player disconnects from the room? So I can show feedback about that
11 Replies
Hi @jos_valentin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To detect when a player disconnects from a room in NormalVR's Normcore, you can use the
RealtimeAvatarManager
component, which provides events that notify you when avatars (representing players) are created or destroyed.
Using RealtimeAvatarManager Events
The RealtimeAvatarManager
includes an avatarDestroyed
event that fires when a player's avatar is removed from the room, which happens when they disconnect. Here's how you can implement this:
This script should be attached to the same GameObject that has the RealtimeAvatarManager
component, which is typically on the same GameObject as your Realtime
instance.
Realtime XR Avatars documentation provides more details about the avatar system and these events.
Server Disconnect Behavior
It's worth noting that when a client crashes or disconnects improperly, the server will detect this after about five seconds:
The server pings connected clients every five seconds. If their connection is dropped suddenly, the server will disconnect them after five seconds and any models that they own that are tagged destroyWhenOwnerLeaves will be destroyed automatically.Architecture Common Questions This means there might be a short delay between when a player actually disconnects and when other clients are notified of the disconnection. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@391444583034257420> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I see, since I am not developing a XR app, Is there a way to handle this without the RealtimeAvatarManager?
you can copy the OnDestroy method in the avatar script
You mean the OnDestroy method in RealtimeAvatar.cs? seems to need the _realtimeAvatarManager

when the remote avatar is destroyed you can fire off an event in OnDestroy using your own manager
With "avatar" you mean a custom object view for my player or something related to the RealtimeAvatarManager?
something you instantiate when a player joins, can be anything
Is there no way to handle this without having instantiated something for the player (I was trying to handle that stuff in a manager with a RealtimeDictionary)
can also be a model if the lifetime flag is destory when player leaves
would be easier to attach it to a gameobject with a script on it though
Ok I'll check if it is posible to use an object to handle with OnDestroy, thanks for the help 🙂