I was trying to set a Player.Profile variable so that I could access it later, but whenever I attempted to read it, it returned empty.
public class LobbyManager : MonoBehaviour
{
private void Awake()
{
InitializeUnityAuthentication();
async void InitializeUnityAuthentication()
{
InitializationOptions initializationOptions = new();
// Profile is set here.
initializationOptions.SetProfile(UnityEngine.Random.Range(0, 10000).ToString());
await UnityServices.InitializeAsync(initializationOptions);
await AuthenticationService.Instance.SignInAnonymouslyAsync();
await AuthenticationService.Instance.UpdatePlayerNameAsync(
UnityEngine.Random.Range(0, 10000).ToString()
);
}
}
private void PrintProfilesAndAName()
{
Debug.Log(JoinedLobby.Players.Count) // Prints '2' as expected (I'm play-testing with 2 instances).
// Prints 'Player Profile: ' for each player...
foreach (Player player in JoinedLobby.Players) Debug.Log("Player profile: " + player.Profile);
Debug.Log(JoinedLobby.Players[0].Profile.Name); // NRE.
}
}
Is that by design? Why? The only solution I found was to save this data inside a PlayerDataObject, however, creating a field from another field that should be accessible in the first place feels redundant and hackish.