fgamez1020
fgamez10207h ago

User disconnection

How do I detect when a user disconnects from the room
2 Replies
kapa.ai
kapa.ai7h ago
Hi @fgamez1020. 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 user disconnects from a room in NormalVR, you can use the RealtimeAvatarManager component. This component provides events that notify you when avatars (representing users) are created or destroyed in the room. Specifically, you can use the avatarDestroyed event to detect when a user disconnects. Here's how you can implement this:
using UnityEngine;
using Normal.Realtime;

public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;

private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
_manager.avatarDestroyed += AvatarDestroyed;
}

private void AvatarDestroyed(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// User disconnected!
Debug.Log("User disconnected: " + avatar.name);
}
}
using UnityEngine;
using Normal.Realtime;

public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;

private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
_manager.avatarDestroyed += AvatarDestroyed;
}

private void AvatarDestroyed(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// User disconnected!
Debug.Log("User disconnected: " + avatar.name);
}
}
In this code, we subscribe to the avatarDestroyed event of the RealtimeAvatarManager. When a user disconnects, their avatar is destroyed, triggering this event. The AvatarDestroyed method will be called, allowing you to handle the disconnection. Remember to attach this script to the same GameObject that has the RealtimeAvatarManager component. It's worth noting that this method detects user disconnections indirectly through avatar destruction. According to the documentation, when a client crashes or their connection is dropped suddenly, the server will disconnect them after five seconds. Any models they own that are tagged with destroyWhenOwnerLeaves will be automatically destroyed. Realtime > Xr > Avatars Architecture > Common Questions ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7h ago
<@1053407831916822528> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?