Integrate avatar into unity scene

Hi there,

There are several ways to pass data between scenes in Unity, and using PlayerPrefs is a simple and effective approach. If you’re new to PlayerPrefs, this YouTube Tutorial (not affiliated with our project) gives a good overview of how PlayerPrefs works.

To save the avatar URL when the avatar is created, you can modify your GameManager script like this:

private void OnAvatarSaved(string avatarId)
{
    avatarCreatorStateMachine.gameObject.SetActive(false);

    var startTime = Time.time;
    avatarObjectLoader = new AvatarObjectLoader();
    avatarObjectLoader.AvatarConfig = inGameConfig;
    avatarObjectLoader.OnCompleted += (sender, args) =>
    {
        AvatarAnimatorHelper.SetupAnimator(args.Metadata.BodyType, args.Avatar);
        DebugPanel.AddLogWithDuration("Created avatar loaded", Time.time - startTime);
    };

    avatarObjectLoader.LoadAvatar($"{Env.RPM_MODELS_BASE_URL}/{avatarId}.glb");

    // Store and save the avatar URL
    var avatarUrl = $"{Env.RPM_MODELS_BASE_URL}/{avatarId}.glb"; 
    PlayerPrefs.SetString("AvatarURL", avatarUrl);
}

To load the avatar in another scene, you’ll need to retrieve the saved URL using PlayerPrefs in your AvatarLoader script (or wherever you’re loading the avatar in the new scene):

//Retrieve the saved avatar URL
string avatarUrl = PlayerPrefs.GetString(“AvatarURL”, “DefaultURL”);

Note that in the above example, “DefaultURL” is a placeholder URL that will be used if no avatar URL is found in PlayerPrefs. You should replace it with an actual default URL or handle the case where the avatar URL is not found.

These instructions should ensure that the avatar URL is passed correctly between scenes, allowing you to load the same avatar without any issues.