Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Troubles showing personalized Oculus Avatar in Editor

Discussion in 'VR' started by PennNeuro, May 3, 2021.

  1. PennNeuro

    PennNeuro

    Joined:
    Feb 3, 2017
    Posts:
    6
    I'm trying to render personalized avatars in the Editor with a test user. I've got an Oculus Quest using Oculus Link.

    I'm using Unity 2019.4.25 and the Oculus XR Plugin 1.8.1. I created an app on the Oculus Developer Dashboard (for the Quest). I've created a few test users. I'm targeting PC/Standalone in build settings, even though I plan on switching to Android. I've logged in with one of the test users to my Quest, and I've logged in on the OculusPlatformSettings. I've put the App ID in the OvrAvatarSettings and OculusPlatformSettings (in both Rift App Id and Quest fields). I customized the Avatar for my test user.

    I perform and pass my entitlement check successfully, then I successfully get my user ID, then I instantiate an Avatar and apply that ID to the OvrAvatar script. I've also tried applying some of the test IDs from the docs page, but I always see the same, unchanging avatar.

    I'm kinda stuck here. Does anyone have any leads?

    Thanks for any help!

    Though they're pretty simple scripts that basically come straight from the docs, here's the code I'm using:

    Code (CSharp):
    1. public class EntitlementChecker : MonoBehaviour
    2. {
    3. //------------------------------------------------------------------------CONSTANTS:
    4.  
    5.     private const string LOG_TAG = "EntitlementChecker";
    6.     public bool VERBOSE = false;
    7.  
    8. //---------------------------------------------------------------------------FIELDS:
    9.  
    10.     [SerializeField]
    11.     private UnityEvent onVerified, onFailed;
    12.  
    13. //---------------------------------------------------------------------MONO METHODS:
    14.  
    15.     void Awake()
    16.     {
    17.         try
    18.         {
    19.             if( ! Core.IsInitialized() )
    20.             {
    21.                 vLog( "Initializing Core" );
    22.                 Core.AsyncInitialize();
    23.                 //Core.Initialize();
    24.             }
    25.             Entitlements.IsUserEntitledToApplication().OnComplete( checkCallback );
    26.         }
    27.         catch( System.Exception e )
    28.         {
    29.             LOG_TAG.TPrint( "Failed initializing core or verifying entitlements: " + e );
    30.             if( onFailed != null )   onFailed.Invoke();
    31.         }
    32.     }
    33.  
    34. //--------------------------------------------------------------------------HELPERS:
    35.  
    36.     void checkCallback( Oculus.Platform.Message message )
    37.     {
    38.         if( message.IsError )
    39.         {
    40.             vLog( "Error checking entitlements: " + message.GetError().Message );
    41.             if( onFailed != null )    onFailed.Invoke();
    42.             return;
    43.         }
    44.  
    45.         vLog( "Successfully verified user's entitlements!" );
    46.         if( onVerified != null )   onVerified.Invoke();
    47.     }
    48.  
    49.     private void vLog( string message )
    50.     {
    51.         if( VERBOSE ) LOG_TAG.TPrint( message );
    52.     }
    53. }
    54.  
    When this passes, it activates a GameObject with the following script on it:
    Code (CSharp):
    1. public class UserAvatar : MonoBehaviour
    2. {
    3. //------------------------------------------------------------------------CONSTANTS:
    4.  
    5.     private const string LOG_TAG = "PlatformManager";
    6.     public bool VERBOSE = false;
    7. //---------------------------------------------------------------------------FIELDS:
    8.  
    9.     [SerializeField]
    10.     private OvrAvatar avatar;
    11.  
    12.     [SerializeField]
    13.     private GameObject avatarPrefab;
    14.  
    15.     public OvrAvatar Avatar { get; private set; }
    16.  
    17.     // Set in getLoggedInUserCallback
    18.     public User UserData { get; private set; }      
    19.  
    20.     public string UserDataString
    21.     {
    22.         get
    23.         {
    24.             if( UserData == null )    return "";
    25.  
    26.             return  "DisplayName: "     + UserData.DisplayName         + ", " +
    27.                     "ID: "                 + UserData.ID                 + ", " +
    28.                     "OculusID: "         + UserData.OculusID         + ", " +
    29.                     "PresenceStatus: "     + UserData.PresenceStatus;
    30.         }
    31.     }
    32.  
    33.     [SerializeField]
    34.     private UnityEvent onLoggedIn, onFailedLogin;
    35.  
    36. //---------------------------------------------------------------------MONO METHODS:
    37.  
    38.     void Awake()
    39.     {
    40.         try
    41.         {
    42.             if( ! Core.IsInitialized() )
    43.             {
    44.                 vLog( "Initializing Core" );
    45.                 Core.AsyncInitialize();
    46.                 //Core.Initialize();
    47.             }
    48.             Users.GetLoggedInUser().OnComplete( getLoggedInUserCallback );
    49.             Request.RunCallbacks();
    50.         }
    51.         catch( System.Exception e )
    52.         {
    53.             LOG_TAG.TPrint( "Failed initializing core or verifying entitlements: " + e );
    54.         }
    55.  
    56.     }
    57.  
    58. //--------------------------------------------------------------------------HELPERS:
    59.  
    60.     private void getLoggedInUserCallback( Message<User> message )
    61.     {
    62.         if( message.IsError )
    63.         {
    64.             LOG_TAG.TPrint( "Error getting logged in user: " +
    65.                             message.GetError().Message );
    66.  
    67.             if( onFailedLogin != null )     onFailedLogin.Invoke();
    68.  
    69.             return;
    70.         }
    71.  
    72.         Avatar = Instantiate( avatarPrefab ).GetComponent<OvrAvatar>();
    73.  
    74.         UserData = message.Data;
    75.         vLog( "Got logged in user:\n " + UserDataString );
    76.         Avatar.oculusUserID = "" + UserData.ID;
    77.         //Avatar.oculusUserID = "10150022857770130";
    78.         Avatar.ShowThirdPerson = true;
    79.  
    80.         if( onLoggedIn != null )    onLoggedIn.Invoke();
    81.  
    82.     }
    83.  
    84.     private void vLog( string message )
    85.     {
    86.         if( VERBOSE ) LOG_TAG.TPrint( message );
    87.     }
    88. }