question

Bob Cowburn avatar image
Bob Cowburn asked

PlayFab C# Unity SDK PlayFabMultiplayerManager.LeaveNetwork,C# Unity PlayFab Party SDK FabMultiplayerManager.LeaveNetwork();

Hi,

We are using PlayFab Party in our peer-to-peer game have a problem when the multiplayer session is ended by the player active as the host.

The host player calls CreateAndJoinNetwork, receives a network id, and broadcasts this id to other players when may wish to join his game. The id broadcasting is done using XBox Live APIs. Everything works fine at this stage, but when the hosting player closes his server (the players who have joined are told to disconnect), and calls PlayFabMultiplayerManager.LeaveNetwork(), the delegate PlayFabMultiplayerManager.OnNetworkLeft is never invoked. Is this expected?

The next problem that occurs is when the same hosting player wants to create a new server, CreateAndJoinNetwork is called, but PlayFabMultiplayerManager.OnNetworkJoined is not invoked.

At this point we have to report an error to the user, as our initialisation state seems to be in error.

Have you any ideas about what is going wrong? We wish to have a clean shutdown at the end of a multiplayer session.

Thanks for any help!

,

Hi,

We are using PlayFab Party in our peer-to-peer game and have a question about PlayFabMultiplayerManager.LeaveNetwork();

When the host in our game creates and joins a network we broadcast the network id to other players (using XBox Live APIs), who can join and everything seems to be fine. When the host closes his server the multiplayer session is over and other players are told to disconnect. The host calls LeaveNetwork, but there is no callback on the delegate PlayFabMultiplayerManager.OnNetworkLeft. Is this expected?

During the same session if the previous host decides to create another server, he calls CreateAndJoinNetwork again, but it's often the case that PlayFabMultiplayerManager.OnNetworkJoined is never invoked. At this point after timing out waiting for the delegate to be invoked, we assume something went wrong and report an error to the user.

My question is, what is the proper use of the API in this case? Logically speaking we need a clean shutdown at the end of a session, so that the next session can start without any problems.

We use SDK 2.95.200914 with Unity + Game Core GDK.

Bob.

sdksphotonmultiplayer
10 |1200

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

Bob Cowburn avatar image
Bob Cowburn answered
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.

Citrus Yan avatar image Citrus Yan commented ·

Great! Happy coding:)

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

I just tested it in my Unity Project, both OnNetworkLeft and OnNetworkJoined are successfully invoked. Did you forget to listen for these events in your code, like this:

var playFabMultiplayerManager = PlayFabMultiplayerManager.Get();

// Listen for this event to know when the SDK has joined the network and can start sending messages.
playFabMultiplayerManager.OnNetworkJoined += OnNetworkJoined;

// Listen for this event to know when the SDK has left the network.
playFabMultiplayerManager.OnNetworkLeft += OnNetworkLeft;

If that’s not your case, please provide the code snippet of yours for us to investigate further ( please also specify the version of Party SDK, Unity & PlayFab SDK you’re using).

BTW, I think you may also this tutorial helpful:

https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/networking/party-unity-plugin-quickstart

And, you can find helps for GDK issues from the XBOX developer forum.

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.

Bob Cowburn avatar image Bob Cowburn commented ·

Hi Citrus, I've added a 'reply' to your post in the 'answer' section below (I will eventually get the hang on this forum, I promise).

If you have time, could you take a look?

To summarize, the problem seems to be how our version of the library handles the network leave state change message.

Btw, how do I tell which version of the Party SDK I'm using (I know the PlayFab SDK version).

Please see below. Many thanks.

0 Likes 0 ·
Bob Cowburn avatar image
Bob Cowburn answered

Hi Citrus,

Thanks for your reply, I'm still having problems with this, upgraded to latest PlayFab SDK.

I can reproduce the problem using this simple code in a test project, running in the editor.

PlayFab SDK 2.97.201014
Unity 2019.4.9f1 + Unity GameCore Scarlett extensions


public class PlayFabLogin : MonoBehaviour
{
    PlayFabMultiplayerManager m_playFabMultiplayerManager;

    public void Start()
    {		 		
	#if !UNITY_EDITOR
	Unity.GameCore.SDK.XGameRuntimeInitialize();
	#endif					 		 

        var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", C        reateAccount = true};
        PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);

 
	m_playFabMultiplayerManager = PlayFabMultiplayerManager.Get();	
	m_playFabMultiplayerManager.LogLevel = PlayFabMultiplayerManager.LogLevelType.Verbose;
			 
	// Callbacks
	m_playFabMultiplayerManager.OnNetworkJoined += OnNetworkJoined;
	m_playFabMultiplayerManager.OnError += OnPlayFabErrorCallback;
	m_playFabMultiplayerManager.OnNetworkLeft += OnNetworkLeft;
    }
 		
    public void Update()
    {
#if !UNITY_EDITOR
        Unity.GameCore.SDK.XTaskQueueDispatch();
#endif			 
    }

    private void OnLoginSuccess(LoginResult result)
    {
        Debug.Log("---------------OnLoginSuccess")
	m_playFabMultiplayerManager.CreateAndJoinNetwork(); 		 
    }

    private void OnLoginFailure(PlayFabError error)
    {         
        Debug.LogError("---------------OnLoginFailure");
        Debug.LogError(error.GenerateErrorReport());
    }

    private void OnNetworkJoined(object sender, string networkId)
    {
	Debug.LogError("---------------OnNetworkJoined");
	StartCoroutine(WaitThenLeave());
    }

    IEnumerator WaitThenLeave()
    {
	yield return new WaitForSeconds(2.5f); 		
	m_playFabMultiplayerManager.LeaveNetwork();
    }

    void OnNetworkLeft(object sender, string networkId)
    {
	Debug.LogError("---------------OnNetworkLeft");
    }

    private void OnPlayFabErrorCallback(object sender, PlayFabMultiplayerManagerErrorArgs args)
    {
	Debug.LogWarning("---------------OnPlayFabErrorCallback");
    }
}

OnNetworkLeft is never called.

The problem seems to be in PlayFabMultiPlayerManager.cs in this section, after calling LeaveNetwork:

line 1840:
case PARTY_STATE_CHANGE_TYPE.PARTY_STATE_CHANGE_TYPE_LEAVE_NETWORK_COMPLETED:
{
    var stateChangeConverted =....     
    if (InternalCheckStateChangeSucceededOrLogErrorIfFailed(stateChangeC...             
        
    ....  

The value of stateChangeConverted.result is :PARTY_STATE_CHANGE_RESULT_LEAVE_NETWORK_CALLED

but InternalCheckStateChangeSucceededOrLogErrorIfFailed only returns true if the result is

PARTY_STATE_CHANGE_RESULT.PARTY_STATE_CHANGE_RESULT_SUCCEEDED

So the callback never occurs.

Any ideas what is causing this? Many thanks - Bob.

3 comments
10 |1200

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

Antonio Franchinotti avatar image Antonio Franchinotti commented ·

Struggled with the same issue this week... I was using PlayFab Party SDK v1.4.8.0-main.0 and this was solved on v1.5.0.1-main.0 (release 11 days ago)

Hope this helps :D

0 Likes 0 ·
Antonio Franchinotti avatar image Antonio Franchinotti commented ·

Note that you have to update PlayFab Party SDK

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan commented ·

I was using v1.5.0.1-main.0 too, could you please try that?

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.