Skip to main content
Shruggger
New Participant
April 29, 2021

(Unity) How to get players OculusID / Username

  • April 29, 2021
  • 2 replies
  • 3629 views

I have been trying to retrieve the username but I can't get anything to work. Here's the program below. It retrieves the user's OculusID and sets a variable that is synced on the network. When this is run, it returns as a null reference exception. 

 

Users.GetLoggedInUser().OnComplete((Message<User> uMsg) =>
                {
    if (uMsg.IsError)
    {
        Debug.LogError("Platform: GetLoggedInUser() failed. Reason: " + uMsg.GetError().Message);
        return;        // no need to go any further if local user can't be determined
    }
    else
    {
        // success, process user structure we receive in uMsg.Data
        newClientClass.nickName = uMsg.Data.OculusID;
    }
});

 

 I cannot find any example code or documentation on how to properly implement this.

2 replies

Up and Coming
February 9, 2022

any update on this? Get it working?

 

prozac
Meta Employee
February 11, 2022

The SharedSpaces Unity sample shows how.

https://github.com/oculus-samples/Unity-SharedSpaces/blob/main/Assets/SharedSpaces/Scripts/SharedSpacesApplication.cs

 

lines 223 to 240

Users.GetLoggedInUser().OnComplete(OnLoggedInUser);
        });
    }

    private void OnLoggedInUser(Message<Oculus.Platform.Models.User> message)
    {
        if (message.IsError)
        {
            LogError("Cannot get user info", message.GetError());
            return;
        }

        // Workaround.
        // At the moment, Platform.Users.GetLoggedInUser() seems to only be returning the user ID.
        // Display name is blank.
        // Platform.Users.Get(ulong userID) returns the display name.
        Users.Get(message.Data.ID).OnComplete(localPlayerState.Init);
    }