Forum Discussion

GamerReality's avatar
GamerReality
Explorer
10 months ago

Accessing Player's Oculus Username and Displaying it in-game.

Hello,

I'm developing a multiplayer VR game for Quest and Windows PCVR. Unity 2023.2.19, XR Plug-in is set to OpenXR, latest XR plugins, and Meta XR Platform SDK 68.0.0.

I've only pieced together loose information online to make this system for grabbing and displaying the player's Oculus/Meta/Account username, but I need help because it's not working. I'm going this route because I don't want to add moderation and check for unique usernames if Meta already has these systems. 

I made sure that the Meta XR Platform SDK was in my project which is the only Meta package I have: Meta XR Platform SDK | Integration | Unity Asset Store

It builds and runs fine, it authenticates successfully thanks to the instructions from here: https://developer.oculus.com/documentation/unity/ps-entitlement-check/

try
{
Core.AsyncInitialize(appID); //Their docs had "Platform.Core.AsyncInitialize(appID), but their example only had ()"
Entitlements.IsUserEntitledToApplication().OnComplete(EntitlementCallback);
}
catch(UnityException e)
{
Debug.LogError("Platform failed to initialize due to exception.");
Debug.LogException(e);
// Immediately quit the application.
UnityEngine.Application.Quit();
}

// Called when the Meta Horizon platform completes the async entitlement check request and a result is available.
void EntitlementCallback (Message msg)
{
if (msg.IsError) // User failed entitlement check
{
// Implements a default behavior for an entitlement check failure -- log the failure and exit the app.
Debug.LogError("You are NOT entitled to use this app.");
UnityEngine.Application.Quit();
}
else // User passed entitlement check
{
// Log the succeeded entitlement check for debugging.
Debug.Log("You are entitled to use this app.");

// From https://communityforums.atmeta.com/t5/Unity-VR-Development/How-do-i-access-oculus-username/td-p/889007
Oculus.Platform.Users.GetLoggedInUser().OnComplete(GetLoggedInUserCallback);
}
}

private void GetLoggedInUserCallback(Message msg) {
if (!msg.IsError) {
User user = msg.GetUser();
Oculus_userName = user.OculusID;
Oculus_displayName = user.DisplayName;

PlayerUsernameWeWillSet = Oculus_displayName;
}
else
{
setDefaultPlayerNameInstead = true;
}
}

But when I try to use PlayerUsernameWeWillSet, it's not null or empty because I have checks to set it to a generic player name instead. I know it can take a few seconds, so I have logic to rerun a coroutine every so often trying to see if we got the username but it's still not getting it. My PCVR version is working with a username I'm grabbing from a different source, it displays properly in a text field.

Maybe you see the problem, but if you don't you can help me know how to debug this and get a log after building it as an APK which I haven't tried yet.

Thank you.

 

5 Replies

  • This may be the problem of you having to upload your APK to the store, and then downloading it from the store

    • GamerReality's avatar
      GamerReality
      Explorer

      Forgot to mention authentication works, I've had it kick me if I sideload it but I publish it to a private alpha channel, download the update, and I'm authenticated in the game.

    • GamerReality's avatar
      GamerReality
      Explorer

      Yes I tried putting those things into place, that's in my third code block in my discussion post. I'll put it again:

      private void GetLoggedInUserCallback(Message msg) {
      if (!msg.IsError) {
      User user = msg.GetUser();
      Oculus_userName = user.OculusID;
      Oculus_displayName = user.DisplayName;

      PlayerUsernameWeWillSet = Oculus_displayName;
      }
      else
      {
      setDefaultPlayerNameInstead = true;
      }
      }
  • This will give you the unique Oculus username. The display name is the user's first and last name if I recall correctly.

    PlayerUsernameWeWillSet = user.OculusID;