- Home /
How can I set the avatar in the animator at runtime?
I see from the documentation that I can set/get an avatar in an animator but I do not know how to select the avatar in order to load it. For example I have two models both have an avatar one is maleAvatar the other is femaleAvatar they are both existing in the unity project and humanoids. I have one character controller that has the animator on it and controls model I load into it and manually set the avatar for but how can i do this at runtime or when the player clicks on which gender they would like? I don't know how to access an avatar to instance it and then use the setter for the animator component.
The game is networked on mirror else i would just create a male and female prefab but seems we should just be able to use that function or am I missing something?
Answer by SamyBoyJim · Oct 03, 2021 at 05:03 AM
You can make a reference to it in your script: [SerializeField] private Avatar _avatar; Then you can set the avatar in the inspector and when you need to, change the avatar.
How can i set the avatar? like what do i have to code in? Ive made a reference but how do i actually switch from avatar1 to avatar2??
You need a reference to your animator by making another variable and assigning that in the inspector. Then, through code, you can go into the animator and there should be an avatar property on it which you can use to get and set the avatar. Hope this helps :)