CreateRoom: FindOrCreate not working?

I am calling CreateRoomAsync, passing in a RoomCreationOptions to specify a tag and setting FindOrCreate to true so it should return an existing room if there is one. Instead it always returns a new room. It appears the value of FindOrCreate is ignored and always false in the coherence code?

        var options = new RoomCreationOptions
        {
            Tags = new[] { _gameModel._id },
            FindOrCreate = true,
        };

        var room = await MenuController.Instance.RoomService.CreateRoomAsync(options);

Expected behaviour

The system should find a room with a matching tag and return the existing room.

Screenshots

How to reproduce

Every time

  1. Call CreateRoomAsync with a string tag, and FindOrCreate = true
  2. Call CreateRoomAsync again with same tag, and FindOrCreate = true

See in room dashboard that it created a second room with same tag, instead of returning existing room.

I found that in CloudRoomsService.cs code it looks like FindOrCreate is hard coded to false on line 504 instead of copying the value from options passed in?

        private string GetRoomCreationRequestBody(RoomCreationOptions roomCreationOptions)
        {
            var requestBody = Utils.CoherenceJson.SerializeObject(new RoomCreationRequest()
            {
                Tags = roomCreationOptions.Tags ?? new string[] { },
                KV =roomCreationOptions.KeyValues ?? new Dictionary<string, string>(),
                Region = region,
                MaxClients = roomCreationOptions.MaxClients,
                SimSlug = runtimeSettings.SimulatorSlug,
                FindOrCreate = false
            });
            return requestBody;
        }

Environment

SDK: 1.1.4
Unity: 2022.3.19
OS/Platform: MacOS

Hi joeskylight - what is your project ID? I’ll take a look at logs on our end.

Project ID: cog4o122t1clkfbfojc0
Thanks!

I’ve brought this up with the SDK team to see about the hard coded value.

2 Likes

We’ve opened a bug issue for this and hope to get it fixed soon. We’ll update here when it’s fixed.

In the meantime, although it’s not the same, you can of course list rooms with the API and join if one exists with a matching tag. Not ideal, but may unblock you.

Additionally, if you plan to introduce Lobbies at any point in your game, our Lobby API also has FindOrCreate and does not have this bug.

Thank you @brit !
Yes, in the mean time I am manually calling FetchRoomsAsync with the tag as a first step and only creating a room if not found. Though I assume the real sdk call would avoid the race condition of multiple clients accidentally creating separate rooms at the same instant.
Thanks for the tip on lobbies also.

Yup, exactly right about the race condition, which is why we have the FindOrCreate in the first place!

1 Like