NPC Avatar
The next section is going to spawn an NPC Avatar using a locally-stored Avatar definition. This will use the Using Multiple Avatars sample scene to create a locally stored Avatar definition.
Open the Sample Scene
In the Project window, open the Assets > Samples > Genies Avatar SDK > X.Y.Z > Sample Starter Scenes > Using Multiple Avatars > Scenes folder. Double click the MultipleAvatars scene to open it.

Play the Scene
Once the scene is opened, press the Play button. Once you are logged in, make sure the default values for the UIs are set to:
- Save Locally & Exit Editor
Test-Profile
Then click one of the Avatars to open the Avatar Editor.

These two UIs are setting the Avatar Editor to save a locally stored Avatar definition under the name Test-Profile once the user clicks the Save button.
Save a Definition
Use the Avatar Editor to create the look of the NPC. Once finished, click the Save button to locally store the definition you created. Exit Play mode.

Find the Test Profile Definition
In the Project window, open the Assets > Genies > AvatarEditor > Profiles > Resources folder. Make sure the Test-Profile definition is successfully created.

Create NPC Spawn Object
Open the SampleScene in the Assets > Scenes folder. Create a new empty Game Object named NpcSpawn.

Create NPC Controller Script
In the Hierarchy window, select the NpcSpawn object. In the Inspector window, click the Add Component button near the bottom and then select the bottom option to New Script. Name the script NpcController.
Then set the Position property to Z: 3 and Rotation property to Y: 180.

Add Code to the Script
Open the NpcController script and add this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Genies.Sdk;
public class NpcController : MonoBehaviour
{
void Start()
{
if (!AvatarSdk.IsLoggedIn)
{
AvatarSdk.Events.UserLoggedIn += LoadNpc;
return;
}
LoadNpc();
}
private void OnDestroy()
{
AvatarSdk.Events.UserLoggedIn -= LoadNpc;
}
private async void LoadNpc()
{
var npcAvatar = await AvatarSdk.LoadFromLocalAvatarDefinitionAsync("Test-Profile");
npcAvatar.Root.transform.parent = this.transform;
npcAvatar.Root.transform.position = this.transform.position;
npcAvatar.Root.transform.rotation = this.transform.rotation;
}
}
The AvatarSdk.LoadFromLocalAvatarDefinitionAsync("Test-Profile"); method is loading the locally stored Avatar definition that you created earlier.
Test the Code
Save the code and enter Play mode. The NPC Avatar should load in front of the player Avatar.
