Updating Lobby Settings

Hello, for some reason this code isn’t working, what I am trying to do is to update the settings of a lobby before a game begins, but for some reason the lobby’s settings don’t get changed at all.
Could you please tell me what I am doing wrong?

public async void begin() {
      Debug.Log($"The hidden join code is {joinCode}");
      LobManager.assignLobby(lobby);

      var x = await Lock();

      Debug.Log($"Privated {lobby.IsPrivate}"); //false
      Debug.Log($"Locked {lobby.IsLocked}"); //false

      networkManager.SceneManager.LoadScene("Game Board", LoadSceneMode.Single);
    }

    private IEnumerator Lock() {
      Debug.Log("Locking");

      UpdateLobbyOptions updateOptions = new UpdateLobbyOptions() {
        IsPrivate = true,
        IsLocked = true
      };

      Debug.Log($"update IsPrivate = {updateOptions.IsPrivate}"); //true
      Debug.Log($"update IsLocked = {updateOptions.IsLocked}"); //true

      var t = Lobbies.Instance.UpdateLobbyAsync(lobby.Id, updateOptions);

      Debug.Log($"t.IsCompleted {t.IsCompleted}"); //false

      yield return new WaitWhile(() => t.IsCompleted == false);

      Debug.Log($"update IsPrivate = {updateOptions.IsPrivate}"); //true
      Debug.Log($"update IsLocked = {updateOptions.IsLocked}"); //true
      Debug.Log($"t.IsCompleted {t.IsCompleted}"); //true
      Debug.Log($"Finish with private = {lobby.IsPrivate}"); //false
      Debug.Log($"Finish with lock {lobby.IsLocked}"); //false
    }

Lobbies.Instance.UpdateLobbyAsync(lobby.Id, updateOptions); actually returns a task that will contain a new instance of the lobby with the updates applied when complete. Right now you are not observing the result of the task. The easiest was to do this would be update your Lock method to return async Task and get the new lobby by awaiting the update lobby call:

private async Task Lock() {
      Debug.Log("Locking");
      UpdateLobbyOptions updateOptions = new UpdateLobbyOptions() {
        IsPrivate = true,
        IsLocked = true
      };
      Debug.Log($"update IsPrivate = {updateOptions.IsPrivate}");
      Debug.Log($"update IsLocked = {updateOptions.IsLocked}");
      var updatedLobby = await Lobbies.Instance.UpdateLobbyAsync(lobby.Id, updateOptions);

      Debug.Log($"Finish with lock {updatedLobby.IsLocked}");
      // update the lobby member to be the updated lobby
      lobby = updatedLobby;
    }

Andy’s solution above is probably the easiest, but if you want to keep the Enumerator pattern you’re using you may be able to do so by using t.Result after the yield return statement instead of lobby which is the same thing as Andy is suggesting, i.e. observing the result of the task.

I’m not super clear around how the IEnumerator from your Lock method is being used, so I don’t know for sure if this’ll do what you want, but in most Async Enumerator patterns that should do the trick.

Alright, Thanks you two for the help!