Skip to main content

Using Multiple Avatars

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

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

From the top menu, select Windows > Package Manager window. Then select Packages: In Project on the top left dropdown and also select the Genies Avatar SDK package on the left side menu.

Click the Samples tab and click the Import button next to the Sample Starter Scenes sample.

Import Sample

Open the Sample Scene

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

Open Scene

Switch to Simulator Window

The sample scenes are optimized for a mobile device. In the Game window, switch the window to Simulator mode and choose a mobile device.

Simulator Window

Play the Scene

Login Anonymously

Press the Play button. Click the Anonymous Login button.

Anon Login

tip

Anonymous login is a feature that allows users to not require a Genies login to use the Genies Avatar SDK.

See the User Login page for more information.

Confirm the Local Avatars Load

Once signed in, there should be two local Avatars loaded.

Two 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 right Avatar 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. There should be a ExampleProfile scriptable object which is the local Avatar definition that was just saved.

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.

Two Avatars

Open the Script

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

Load Script

Edit the Script

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

private string _profileId1 = "ExampleProfile";
note

These initial Avatars are using sample definitions stored in the Assets > Sample > Genies Avatar SDK > X.Y.Z > Sample Starter Scenes > 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.