Lobby Is using Previous Auth Information when testing multiple times

Im using Unitys auth and lobby services. for local testing I use anonymous sign in with random profiles.
image
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:
image

Second login:
image

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

Please post text as text, not screenshots! Screenshots are not quotable, editable, searchable and hard to read.

Please also post the code you use to sign in. You know about the session token that signs in the previously signed in player? Do you also run code to sign out the player on shutdown?
It’s also not clear what kind of ID you are logging.

1 Like

Understood, updated the post to reflect relative code snippets. I did infact try to sign the player out on shutdown, which resulted in an even weirder behaviour where After login i would get 401 in the lobby create request.

The ID I am logging is the userID from loginAnonymous,

Note that this might theoretically also fail, so try/catch that too!

Sign out can be done with or without clearing the token. If you clear the token, every new anonymous sign in will create a new player ID. You don’t want that because any progress attached to that anonymous player would be lost.

Other than that I guess we’d have to know more about the flow of instructions, which might get too complex to debug here. In my experience most issues arise from an unusual sequence of operations, or timing issues. Maybe try stripping it down to barebones functionality. And be sure to close the Lobby when closing the app.

Thanks for the try catch advice, i integrated with that.

But the core issue ended up being a small unity bug related to domain reloading, for now I reenabled it. Unity - Manual: Domain Reloading and unity team said theyll solve the issue at some point.

Thanks for taking a look!