Alix Ollivier
Alix Ollivier8h ago

Is there a way to swap avatars?

I'm adding avatar skins to my game, so a fruit bat vs a vampire bat. I'd like to be able to press a button and swap the avatar on the normcoreplayer. Is there a function to allow this?
4 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: ---------------------- Normcore does not provide a built-in function to directly swap the avatar prefab for a player at runtime. The avatar prefab is instantiated by the RealtimeAvatarManager when a client joins the room, and it expects the prefab to be set via the localAvatarPrefab property before the avatar is created. If you want to allow players to swap between different avatar skins (like a fruit bat vs. a vampire bat), you have a couple of options: 1. Change the Avatar Prefab and Reconnect:
You can set the localAvatarPrefab property on the RealtimeAvatarManager to your new avatar prefab and then force the local avatar to be destroyed and recreated. This typically involves disconnecting and reconnecting the avatar, which may not be seamless for the user. 2. Swap Skins Within a Single Avatar Prefab:
A more user-friendly approach is to design your avatar prefab to support multiple skins. For example, you can include both the fruit bat and vampire bat models as children of your avatar prefab and enable/disable them as needed when the player presses a button. This way, you don't need to destroy and recreate the avatar; you simply change which skin is visible. This approach is common in Unity and works well with Normcore, as the networked avatar remains the same, and only the appearance changes locally and for other players. 3. Custom Synchronization:
If you want other players to see the skin change, you should synchronize the selected skin index or type using a custom property on a RealtimeModel. When the property changes, all clients update the visible skin accordingly. Summary:
There is no built-in "swap avatar" function in Normcore, but you can implement avatar skin swapping by either changing the prefab (with a reconnect) or, preferably, by toggling skins within a single prefab and synchronizing the selection using a custom model property. For more details on creating custom avatars and synchronizing custom data, see the XR Avatars and Voice Chat guide and the Synchronizing Custom Data guide. If you need a code example or more details on synchronizing the skin selection, let me know! ---------------------- 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
you can chance the localPlayerPrefab on RealtimeAvatarManager and it will destroy the old instance and spawn a new one, but for more fine grained control, you need to build this functionality into your avatar prefab
Alix Ollivier
Alix OllivierOP8h ago
ty max

Did you find this page helpful?