04-29-2021 05:43 AM - last edited on 10-30-2021 06:52 PM by mouse_bear
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.
02-09-2022 09:42 AM
any update on this? Get it working?
02-10-2022 05:49 PM
The SharedSpaces Unity sample shows how.
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);
}