Total players in a room in DidConnectToRoom
How to get the total players connected to a room on the DidConnectToRoom method?
2 Replies
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 get the total number of players connected to a room in the
DidConnectToRoom method, you can use the RealtimeAvatarManager component. This component lives in the scene on the same game object as your Realtime instance and is responsible for keeping track of avatars that were instantiated for other players in the same room.
The RealtimeAvatarManager keeps track of all avatars in the room via the avatars property. This property is a dictionary of all RealtimeAvatar components stored under the clientID that the avatar belongs to. You can use this to determine how many players are currently in a multiplayer space.
Here is an example of how you can use it:
In the AvatarCreated method, we log the total number of players in the room by getting the count of the avatars dictionary.
Please note that this will give you the total number of players in the room at the time an avatar is created. If you want to get the total number of players in the room at any given time, you can directly access the avatars property of the RealtimeAvatarManager.
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:
----------------------<@1053407831916822528> Kapa.ai is still learning and improving, please let me know how I did by reacting below.