Alix Ollivier
Alix Ollivier8h ago

onavatardestroyed never called

I am trying to make a LocalPlayerRegistry script that has a list of all players in the Normcore Room with their Meta display name and clientID attached. I am using RealtimeAvatarManager to get a list of all players, but for some reason if Client A and Client B are in the same room, and Client B leaves, Client A never gets an OnAvatarDestroyed event from the RealtimeAvatarManager.
8 Replies
kapa.ai
kapa.ai8h ago
Hi @Alix Ollivier. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources, the avatarDestroyed event on RealtimeAvatarManager should be called when an avatar is destroyed, such as when a client leaves the room. The typical usage is to subscribe to avatarCreated and avatarDestroyed events in your script, as shown in the documentation:
private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
_manager.avatarCreated += AvatarCreated;
_manager.avatarDestroyed += AvatarDestroyed;
}
private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
_manager.avatarCreated += AvatarCreated;
_manager.avatarDestroyed += AvatarDestroyed;
}
If you are not receiving the avatarDestroyed event when another client disconnects, here are some things to check: 1. Prefab Setup: Ensure your avatar prefab includes a RealtimeAvatar component on the root. The RealtimeAvatarManager relies on this to track and manage avatars properly. 2. Ownership and Lifetime Flags: The default behavior is for the root RealtimeView of the avatar to have destroyWhenOwnerLeaves set to true. If you have changed this value or cleared the owner of the avatar, the server will not clean up the avatar properly, and the avatarDestroyed event may not fire as expected. Double-check that your avatar prefab’s root RealtimeView has destroyWhenOwnerLeaves enabled. This is mentioned explicitly in the documentation:
The root RealtimeView is set to destroyWhenOwnerLeaves by default. If you change this value, or if you clear the owner of the avatar itself, then it will not be cleaned up properly by the server.
XR Common Questions 3. Correct Event Subscription: Make sure you are subscribing to the event before connecting to the room and that you are not accidentally unsubscribing or missing the event due to script execution order. If all of the above are set up correctly and you are still not receiving the event, it may be worth checking for errors in the console or reviewing your prefab and scene setup for any deviations from the recommended configuration. Summary:
The most common cause for avatarDestroyed not firing is that the avatar’s root RealtimeView does not have destroyWhenOwnerLeaves set to true, or ownership is not set up correctly. Double-check these settings in your prefab and ensure your event subscription is active before connecting to the room.
XR Common Questions
XR Avatars Reference ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8h ago
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
maxweisel
maxweisel8h ago
Do you see the avatar get destroyed?
Alix Ollivier
Alix OllivierOP8h ago
we see the avatar as disabled, but not destroyed
maxweisel
maxweisel8h ago
RealtimeAvatar’s OnDestroy() calls RealtimeAvatarManager’s avatarDestroyed event. the source code is included. it’s hard to imagine how the event doesn’t fire as long as the avatar prefab is destroyed then you’ve got something else going on. Normcore doesn’t disable prefabs in response to anything I expect it’s not being destroyed on the owning client side either then
Alix Ollivier
Alix OllivierOP8h ago
yeah this seems to be the source of the issue, we messed with it somewhere. Thanks for the heads up!
No description
Alix Ollivier
Alix OllivierOP8h ago
@Max My cursor is telling me that this "Scene View Destroy" when Last Client Leaves" should be unchecked, does that seem right? I don't remember ever touching this and I could only find it through the unity debug, so I want to be cautious.
No description
maxweisel
maxweisel8h ago
that has no affect on prefabs only on views that exist in the scene

Did you find this page helpful?