Im using Unitys auth and lobby services. for local testing I use anonymous sign in with random profiles.
So each time i open the game i have a new profile.
When i originally test the game, it logs in with a new profile, I can create a new lobby and im the host of that lobby.
But when i shutdown and reopen the editor game, and get a brand new profile with a new ID,
when i call create lobby function on my second attempt the lobby host is the old profile…
First login:
Second login:
as you can see, old account id is the host of the new lobby…
Edit:
Here is code instead of pictures:
using
public class UGSManager : MonoBehaviour
{
// Start is called before the first frame update
async void Awake()
{
var options = new InitializationOptions();
var profile = Random.Range(0, 10000000).ToString();
Debug.Log(profile);
options.SetProfile(profile);
await UnityServices.InitializeAsync(options);
gameObject.AddComponent<UGSAccountManager>();
gameObject.AddComponent<UGSLobbyManager>();
}
}
this my UGS starter, ran originally
{
var resp = new LoginAnonymousResponse();
try
{
await AuthenticationService.Instance.SignInAnonymouslyAsync();
AccountInfo account = new AccountInfo();
account.ID = AuthenticationService.Instance.PlayerId;
account.Token = AuthenticationService.Instance.AccessToken;
account.Username = AuthenticationService.Instance.PlayerName;
Debug.Log($"SIGNED IN AS {account.ID}, {account.Username}");
resp.accountInfo = account;
Debug.Log($"{account.ID}, {account.Username}");
return resp;
}
catch (Exception e)
{
throw new LoginAnonymousException($"Login anonymous failed, exception= {e.Message}");
}
}
this is account login code, called from another script (before lobby is created, but after UGS is inited)
public async Task<CreateLobbyResponse> CreateLobby()
{
try
{
var resp = new CreateLobbyResponse();
string lobbyName = "MyLobby";
int maxPlayers = 100;
var options = new CreateLobbyOptions();
joinedLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers);
Debug.Log($"Created lobby with host id {joinedLobby.HostId}");
lobbyInfo = new LobbyInfo
{
lobbyID = joinedLobby.Id
};
resp.lobbyInfo = lobbyInfo;
return resp;
}
catch (Exception e)
{
throw new CreateLobbyException($"Failed to create lobby, exception={e.Message}");
}
}
finally this is my lobby code