Ryan Green
Ryan Green2mo ago

Client Connections

Is there a way to know when another client connects?
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @Ryan Green. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, there is a way to know when another client connects in NormalVR. You can use the Realtime component and its didConnectToRoom event. This event is triggered when the Realtime component successfully connects to a room. Here is an example of how you can use it:
using UnityEngine;
using Normal.Realtime;

public class PlayerManager : MonoBehaviour {
private Realtime _realtime;

private void Awake() {
// Get the Realtime component on this game object
_realtime = GetComponent<Realtime>();

// Notify us when Realtime successfully connects to the room
_realtime.didConnectToRoom += DidConnectToRoom;
}

private void DidConnectToRoom(Realtime realtime) {
// This function will be called when the client successfully connects to the room
}
}
using UnityEngine;
using Normal.Realtime;

public class PlayerManager : MonoBehaviour {
private Realtime _realtime;

private void Awake() {
// Get the Realtime component on this game object
_realtime = GetComponent<Realtime>();

// Notify us when Realtime successfully connects to the room
_realtime.didConnectToRoom += DidConnectToRoom;
}

private void DidConnectToRoom(Realtime realtime) {
// This function will be called when the client successfully connects to the room
}
}
In this example, the DidConnectToRoom function will be called when the client successfully connects to the room. You can put any code you want inside this function to handle the event of a client connecting. Please note that this event is triggered when the local client connects to the room. If you want to know when any client (including remote clients) connects to the room, you would need to implement a custom solution using the Normcore's datastore to share the connection state of each client. For more information, you can refer to the Realtime API documentation (https://normcore.io/documentation/realtime) and the Creating a Player Controller guide (https://normcore.io/documentation/guides/creating-a-player-controller#making-it-multiplayer). ---------------------- 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
Mechabit
Mechabit2mo ago
you can register to the avatarmanager's avatar created event