How to know if other players disconnect from room?
How to know if other players disconnect from room?
6 Replies
Hi @Phạm Tuấn Anh. 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 other players disconnect from a room in Normcore, you can use the RealtimeAvatarManager component. This component provides the avatarDestroyed event, which is triggered whenever an avatar (representing a player) is destroyed—typically when a player disconnects from the room. Here’s an example of how to use it:
This approach allows you to respond immediately when another player leaves the room, as their avatar will be destroyed and the event will fire. For more details, see the documentation on avatars and RealtimeAvatarManager Realtime > XR > Avatars.
If you need to track the number of players, you can also use the avatars property of RealtimeAvatarManager, which is a dictionary of all current avatars in the room. When a player disconnects, their entry will be removed from this dictionary.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@1120683104592465930> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant is there any other ways?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Based on the available knowledge sources, the primary documented way to detect when other players disconnect from a room in Normcore is through the RealtimeAvatarManager’s avatarDestroyed event, as previously described.
There is no explicit mention in the documentation of alternative built-in events or callbacks specifically for detecting remote client disconnections at a lower level (such as via the Realtime or Room classes). The Realtime component does provide didDisconnectFromRoom, but this event only notifies you when your own client disconnects from the room, not when other clients do.
If you need more granular control or want to track all players, you can monitor the avatars property of RealtimeAvatarManager, which reflects the current set of connected avatars (players). When a player disconnects, their avatar is removed from this dictionary, which you can check as needed.
To summarize:
- The recommended and documented approach is to use RealtimeAvatarManager’s avatarDestroyed event. - There is no mention of other direct, built-in methods for detecting remote player disconnections in the provided documentation. - For advanced or custom needs, you may need to implement your own tracking logic based on avatar presence. If you require a different mechanism, the knowledge sources do not provide further alternatives. If you have a specific use case, you may want to ask in the Normcore Discord for community solutions or undocumented approaches. Realtime > XR > Avatars ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
- The recommended and documented approach is to use RealtimeAvatarManager’s avatarDestroyed event. - There is no mention of other direct, built-in methods for detecting remote player disconnections in the provided documentation. - For advanced or custom needs, you may need to implement your own tracking logic based on avatar presence. If you require a different mechanism, the knowledge sources do not provide further alternatives. If you have a specific use case, you may want to ask in the Normcore Discord for community solutions or undocumented approaches. Realtime > XR > Avatars ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@1120683104592465930> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
This is the correct way to do it. or to recreate this pattern in your own scripts