cancel
Showing results for 
Search instead for 
Did you mean: 

(Unity) How to get players OculusID / Username

Shruggger
Explorer

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 2

foxvalleysoccer
Protege

any update on this? Get it working?

 

pro_zac
Heroic Explorer

The SharedSpaces Unity sample shows how.

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

 

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);
    }