Chesco
Chesco3mo ago

Change the Local Prefab Avatar

In the Realtime Avatar Manager class, how do I change the Local Prefab Avatar at runtime?
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Chesco. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To change the Local Prefab Avatar at runtime in the RealtimeAvatarManager class, you can modify the localAvatarPrefab property from your own scripts. This property represents the avatar prefab that is instantiated to represent the local client. Here's an example of how you might do this:
public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;
public GameObject newAvatarPrefab; // Your new avatar prefab

private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
}

private void ChangeAvatar() {
_manager.localAvatarPrefab = newAvatarPrefab;
}
}
public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;
public GameObject newAvatarPrefab; // Your new avatar prefab

private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
}

private void ChangeAvatar() {
_manager.localAvatarPrefab = newAvatarPrefab;
}
}
In this example, newAvatarPrefab is the new avatar prefab you want to use. The ChangeAvatar method changes the localAvatarPrefab property of the _manager to the newAvatarPrefab. Remember, the new avatar prefab needs to include a RealtimeAvatar component on the root in order to function correctly. 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: ----------------------
kapa.ai
kapa.ai3mo ago
<@584767573556592640> kapa.ai is still learning and improving, please let us know how it did by reacting below