how can I get the number of players connected to a room?
I create a room and when a new player joins I want to know what number of player that user is so I can assign an avatar according to that player number.
5 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:
----------------------
You can keep track of the number of players in a room using the
RealtimeAvatarManager
component. This component lives in the scene on the same game object as your Realtime
instance and 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
keeps track of all avatars in the room via the localAvatar
and avatars
properties. The avatars
property is a dictionary of all RealtimeAvatar
components stored under the clientID
that the avatar belongs to. This can be useful for determining how many players are currently in a multiplayer space.
Here is an example of how you can use the RealtimeAvatarManager
to track the number of players:
In this example, whenever a new avatar is created or destroyed, the total number of avatars is logged. This number represents the number of players in the room.
Please note that getting a list of all rooms and how many players are in them is something that is currently not supported directly by Normcore and you'll need to manage it yourself.
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 us know how it did by reacting below
how can i change materials on a created avatar
do this:
renderer.material = materials[realtime.clientID];