question

jj-1 avatar image
jj-1 asked

Unity3d CreateAndJoinLobby Doesn't Call Callbacks

I'm having trouble creating a lobby. I get to the OnLoginSuccess without any issue. There's no errors when I create and join the lobby, but it never calls the success or failure. Any one have any ideas?

 using UnityEngine;
 using PlayFab;
 using PlayFab.Multiplayer;
 using PlayFab.ClientModels;
    
 public class Testing : MonoBehaviour
 {
    
     private void OnGUI()
     {
         if (GUILayout.Button("Login"))
         {
             var request = new LoginWithCustomIDRequest { CustomId = UnityEngine.Random.value.ToString(), CreateAccount = true };
             PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);
         }
     }
    
     private void OnLoginSuccess(LoginResult result)
     {
         Debug.Log("OnLoginSuccess");
         PlayFabMultiplayer.Initialize();
    
         string entityId = result.EntityToken.Entity.Id; // PlayFab user's entity Id
         string entityType = result.EntityToken.Entity.Type; // PlayFab user's entity type
    
         PlayFabMultiplayer.SetEntityToken(result.AuthenticationContext);
    
         PlayFabMultiplayer.OnLobbyCreateAndJoinCompleted += this.PlayFabMultiplayer_OnLobbyCreateAndJoinCompleted;
         PlayFabMultiplayer.OnLobbyDisconnected += this.PlayFabMultiplayer_OnLobbyDisconnected;
    
         var createConfig = new LobbyCreateConfiguration()
         {
             MaxMemberCount = 6,
             OwnerMigrationPolicy = LobbyOwnerMigrationPolicy.Manual,
             AccessPolicy = LobbyAccessPolicy.Public
         };
    
         createConfig.LobbyProperties["Prop1"] = "Value1";
         createConfig.LobbyProperties["Prop2"] = "Value2";
    
         var joinConfig = new LobbyJoinConfiguration();
         joinConfig.MemberProperties["MemberProp1"] = "MemberValue1";
         joinConfig.MemberProperties["MemberProp2"] = "MemberValue2";
    
         PlayFabMultiplayer.CreateAndJoinLobby(
             new PFEntityKey(
                 entityId,
                 entityType),
             createConfig,
             joinConfig);
     }
    
     private void OnLoginFailure(PlayFabError error)
     {
         Debug.Log(error);
     }
    
     private void PlayFabMultiplayer_OnLobbyCreateAndJoinCompleted(Lobby lobby, int result)
     {
         Debug.Log("OnLobbyJoined");
         if (LobbyError.SUCCEEDED(result))
         {
             // Lobby was successfully created
             Debug.Log(lobby.ConnectionString);
             PlayFabMultiplayer.Uninitialize();
         }
         else
         {
             // Error creating a lobby
             Debug.Log("Error creating a lobby");
         }
     }
    
     private void PlayFabMultiplayer_OnLobbyDisconnected(Lobby lobby)
     {
         // Disconnected from lobby
         Debug.Log("Disconnected from lobby!");
     }
    
    
 }
unity3d
10 |1200

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

1 Answer

·
Neils Shi avatar image
Neils Shi answered

I tested your code, and it works fine. The lobby connection string displays in the Console window successfully. Have you followed our documentation to drag and drop PlayfabMultiplayerEventProcessor into a scene in the Hierarchy window? For more info, you can refer to Set up your scene.

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.

jj-1 avatar image jj-1 commented ·

It was the prefab thanks!

0 Likes 0 ·

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.