How can I get the remote ID that an avatar represents?
In the
AvatarCreated function avatar.ownerIDSelf returns -1 and avatar.realtime.clientID returns the ID of the local realtime not the remote. I need the ID of the remote client that the avatar is representing.6 Replies
Hi @Voltaia. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
RealtimeAvatar component has a property called ownerIDSelf which represents the client ID of the component owner. However, as you mentioned, it seems to return -1 when accessed in the AvatarCreated function. This might be because the ownership hasn't been established yet at the time this function is called.
One way to handle this is to listen for the ownerIDSelfDidChange event on the RealtimeAvatar component. This event is dispatched when the ownerIDSelf value changes, which should happen when the avatar's ownership is established.
Here's an example of how you might set this up:
This way, you'll be notified when the ownerIDSelf value changes, and you should be able to get the correct client ID of the remote avatar.
Please note that this code is based on the information provided in the RealtimeAvatarManager (https://normcore.io/documentation/realtime/xr/avatars#realtimeavatarmanager) and RealtimeComponent<TModel> (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeComponent%601) documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@276154194606424064> kapa.ai is still learning and improving, please let us know how it did by reacting below
@Normcore Assistant but I don't need necessarily what client actually owns the avatar, rather which client the avatar represents. I understand this is the same, but is there any way to get it independently?
Let me check the knowledge base for you. One moment! :books:
----------------------
In NormalVR, the avatar represents the client that owns it. The
ownerIDSelf property of the RealtimeAvatar component is used to identify the client that the avatar represents. This is because when an avatar is created, the ownership of the root RealtimeView is set to the local client. Therefore, the ownerIDSelf property of the avatar should correspond to the client ID of the client that the avatar represents.
However, if you want to get the client ID independently, you can use the clientID property of the Realtime component. The Realtime component is responsible for managing the connection to the Normcore server and it has a clientID property that represents the client ID of the local client.
Here's an example of how you can access it:
Please note that this will give you the client ID of the local client, not the remote client that the avatar represents. If you need to get the client ID of the remote client that the avatar represents, you should use the ownerIDSelf property of the RealtimeAvatar component as explained in the previous answer.
For more information, you can refer to the RealtimeAvatarManager (https://normcore.io/documentation/realtime/xr/avatars#realtimeavatarmanager) and Realtime (https://normcore.io/documentation/reference/classes/Normal.Realtime.IRealtimeComponent) documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@276154194606424064> kapa.ai is still learning and improving, please let us know how it did by reacting below
Ah I needed to use
avatar.realtimeView