Ryan Green
Ryan Green2mo ago

is it possible to detect when another client joins?

are all clients notified when a user joins a room?
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @Ryan Green | MONA. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to detect when another client joins a room in NormalVR. This can be achieved using the RealtimeAvatarManager component. This component is responsible for instantiating an avatar prefab to represent the local player as well as keeping track of avatars that were instantiated for other players in the same room. The RealtimeAvatarManager includes two events: avatarCreated and avatarDestroyed, which are triggered when players join and leave respectively. You can subscribe to these events to get notified when a player joins or leaves the room. Here is an example of how to use these events:
using UnityEngine;
using Normal.Realtime;

public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;

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

private void AvatarCreated(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// Avatar created!
}

private void AvatarDestroyed(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// Avatar destroyed!
}
}
using UnityEngine;
using Normal.Realtime;

public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;

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

private void AvatarCreated(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// Avatar created!
}

private void AvatarDestroyed(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// Avatar destroyed!
}
}
In this example, the AvatarCreated method will be called when a new player joins the room, and the AvatarDestroyed method will be called when a player leaves the room. You can add your own logic inside these methods to handle these events. For more information, you can refer to the RealtimeAvatarManager documentation (https://normcore.io/documentation/realtime/xr/avatars#realtimeavatarmanager). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@337874773742845953> kapa.ai is still learning and improving, please let us know how it did by reacting below