Skip to main content

Using Multiple Avatars

This tutorial will show you a sample scene named Using Multiple Avatars. It will break down how to use Avatar definitions.

It will cover these topics:

info

This page will be using version X.Y.Z of the Genies SDK Avatar package, but replace it with the latest package version.

Test the Sample Scene

Import the Sample Scene

Select from the top dropdown menu Windows > Package Manager. Select the Genies SDK Avatar package and open the Samples tab. Then click the Import button next to Using Multiple Avatars.

Import Sample

Open the Sample Scene

Once the sample is imported, open the MultipleAvatars scene in the Assets > Sample > Genies SDK Avatar > X.Y.Z > Using Multiple Avatars > Scenes folder.

Open Scene

Play the Scene

With the scene open, enter Play mode. Log in to your Genies account using the email sign in. Once signed in, there should be three local Avatars loaded.

Three Avatars

info

These local Avatars are loaded using the LoadFromLocalGameObjectAsync function with a specific profile name that matches the name of a scriptable object with the Avatar definition.

Save The Local Definition

Set the Profile Name

At the bottom right of the Game window, change the name to ExampleProfile. This input field sets the name of the scriptable object with the saved Avatar definition.

Set Profile

Set the Avatar Editor Save

At the top left, set the dropdown menu to Save Locally & Continue Editing. This allows the Save button in the Avatar Editor to save the Avatar definition to a local scriptable object.

Set Save

info

By selecting this option, it will call the SetEditorSaveLocallyAndContinueAsync() function with the inputted profile name from the step before.

Open Avatar Editor

Select the farthest right of the three Avatars by clicking it. The Avatar Editor should open and focus on the selected Avatar.

Avatar Editor

Edit the Hair Color

Select the Avatar button. Then select the Hair tab and change the color to green.

Edit Hair

Edit the Body Shape

Select the Shape tab and change the body shape to a larger size.

Edit Body

Save the Definition

Click the Save button at the top right. In the Project window, open the Assets > Genies > AvatarEditor > Profiles > Resources folder and select the ExampleProfile scriptable object. In the Inspector window, you can see the saved data including the new hair color and body shapes selected.

Save Definition

info

This folder will always contain any locally saved Avatar definitions.

Load the Local Definition

Replay the Scene

Exit Play mode. If you enter Play mode again, then the Avatar that was saved will revert back to normal. This is because the code is loading from a different Avatar definition than the recently saved one.

Replay Scene

Open the Script

In the Project window, open the Assets > Sample > Genies SDK Avatar > X.Y.Z > Using Multiple Avatars > Scripts folder. Then double click the ThreeAvatarSpawner.cs script to open it.

Load Script

Edit the Script

On line 27, change the name of the profile ID for the first Avatar to ExampleProfile.

private string _profileId1 = "ExampleProfile";
note

These three initial Avatars are using sample definitions stored in the Assets > Sample > Genies SDK Avatar > X.Y.Z > Using Multiple Avatars > AvatarProfiles > Profiles > Resources folder.

Play the Scene

Save the code and enter Play mode. The first right Avatar should be loaded with the saved Avatar definition from before.

Final Test

Conclusion

Now that you understand how to save and load a local Avatar definition, this can be used to store Avatar templates or spawn NPCs with a specific Avatar definition.