question

zreederem avatar image
zreederem asked

Not finding any lobbies through the REST API

I'm trying to use the REST API in Unity to create and find lobbies, but even though I can successfully create a lobby and connect to it as the owner, every call to FindLobbies returns zero results.

The API requests do include the X-EntityToken header, and I don't see any errors, so I'm not sure what I might be doing wrong.


(I'm not currently using the Unity Lobbies SDK for this because that doesn't seem to work on Android.)

I have a public repo here in case more context is useful, but below is the function that attempts to find the lobbies:

public static bool FindLobbies(string search, 
    Action<List<LobbySummary>> onSuccessCallback, 
    Action<string> onErrorCallback
){
    if (PlayerEntity.LocalPlayer != null){
        OnScreenMessage.SetText("Finding Lobbies...");
        var requestProps = new FindLobbiesRequest {};
        PlayFabMultiplayerAPI.FindLobbies(
            requestProps,
            r => APIOnLobbyFindLobbiesCompleted(r, onSuccessCallback),
            e => Debug.LogError(e.GenerateErrorReport())
        );
        return true;
    }
    return false;
}


private static void APIOnLobbyFindLobbiesCompleted(
    FindLobbiesResult result, 
    Action<List<LobbySummary>> callback
){
    ExtDebug.LogJson("APIOnLobbyFindLobbiesCompleted", result);
    callback?.Invoke(result.Lobbies);
}

And this is the function that creates the lobby:

public static void CreateAndJoinLobby(
    string name,
    string level,
    uint maxPlayers,
    bool isInvisible,
    bool isPublic,
    Action<PlayFab.MultiplayerModels.Lobby> successCallback,
    Action<string> errorCallback
){
    OnScreenMessage.SetText($"Creating lobby: {name}...");
    PlayFabMultiplayerAPI.CreateLobby(
        new CreateLobbyRequest {
            MaxPlayers = maxPlayers,
            OwnerMigrationPolicy = OwnerMigrationPolicy.Automatic,
            AccessPolicy = isPublic ? AccessPolicy.Public : AccessPolicy.Private,
            SearchData = new Dictionary<string, string>{
                {LobbyWrapper.LOBBY_NAME_SEARCH_KEY, name},
                {LobbyWrapper.LOBBY_LEVEL_SEARCH_KEY, level},
                {LobbyWrapper.LOBBY_VISIBILITY_SEARCH_KEY, (
                    isInvisible ? ((int)LobbyWrapper.LobbyVisibility.Invisible) 
                    : ((int)LobbyWrapper.LobbyVisibility.Visible)
                ).ToString()},
            },
            LobbyData = new Dictionary<string, string>{
                {LobbyWrapper.LOBBY_NAME_KEY, name},
                {LobbyWrapper.LOBBY_LEVEL_KEY, level},
                {LobbyWrapper.LOBBY_SESSION_KEY, Guid.NewGuid().ToString()},
            },
            Owner = PlayerEntity.LocalPlayer.entityKey,
            UseConnections = true,
            Members = new List<Member>{
                new Member {
                    MemberData = new Dictionary<string, string>{
                        {PlayerEntity.PLAYER_NAME_KEY, PlayerEntity.LocalPlayer.name}
                    },
                    MemberEntity = PlayerEntity.LocalPlayer.entityKey,
                }
            }
        },
        r => _OnLobbyCreated(r, successCallback, errorCallback),
        e => OnError(e, errorCallback)
    );
}
unity3dmultiplayer
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

zreederem avatar image zreederem commented ·

I just noticed that the FindLobbies function works if the lobby was created using the Lobbies SDK instead of the REST API. I think I'll do some more debugging to see if I can figure out what the difference is.

0 Likes 0 ·
Gosen Gao avatar image
Gosen Gao answered

By default, the Lobby needs a connected entity to be searchable. For more details, please see UseConnections section in CreateLobby API.

Unity PlayFab SDK is based on RESTful API and can't be used to establish the connections. To create a connected Lobby, please use PlayFab Multiplayer SDKs.

Otherwise, if you do not need real-time notifications, you can set UseConnections to false and also OwnerMigrationPolicy to None, then lobbies do not need connections to be searchable.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

narekk13 avatar image narekk13 commented ·

Please answer to @locnguyen question: But is it not available on Android/IOS what should I do ?

0 Likes 0 ·
locnguyen avatar image
locnguyen answered

But is it not available on Android/IOS what should I do ?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.