Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Matthew Tighe · Nov 24, 2020 at 03:10 PM · unity3d

PlayFab Party in Unity - Network Teardown on Error

Hello,

We are using PlayFab Party in Unity and having a major problem when any kind of network issue or re-connection occurs.

Whenever we then try to create a Network with CreateAndJoinNetwork this will either just never callback, or OnError will fire with one of the following error codes:

4098 = the operation was called with an invalid handle
4330 = an unknown error code was returned by the PlayFab service

We always try to leave any network before we create another, I cannot see any other methods to call to tear anything down or reset it?

Any help greatly appreciated.

Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Citrus Yan ♦ · Nov 25, 2020 at 05:24 AM 0
Share

May I know your title id and the version of the Party SDK you're using? And, do you mind sharing the code snippet you're using that reproduces this issue?

4 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Matthew Tighe · Nov 26, 2020 at 01:52 AM

Hi Citrus,

The TitleId is: 58956 and we are using playfab-party.1.5.0.1-main.0-10.27.2020-preview for Unity.

Our game is targeting Windows Gamecore using the GDK. We ran the GDK install script in the PlayFabParty plugin for Unity as described. Perhaps there is something there we could verify?

In terms of reproduction, this issue happens either in real builds or in the Editor.

On Start of our scene, we register the PlayFabParty listeners:

    public void Start()
    {
        if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.TitleId))
        {
            PlayFabSettings.staticSettings.TitleId = "58956";
        }
        PlayFabMultiplayerManager.Get().OnNetworkJoined += OnNetworkJoined;
        PlayFabMultiplayerManager.Get().OnNetworkLeft += OnNetworkLeft;
        PlayFabMultiplayerManager.Get().OnError += OnPlayFabError;
    }

Upon user pressing a "Start Matchmaking" button, the game logs in:

if(lastLoginResult == null || !PlayFabClientAPI.IsClientLoggedIn()){  var request = new LoginWithCustomIDRequest {    CustomId = PlayerId, CreateAccount = true  };
  PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure);
}

Note that in builds we are using XboxLive Authentication, in the Editor we are using a CustomId Authentication just for testing. But the flow is identical.

We cache the lastLoginResult and also try to validate the client is logged in. But removing that makes no difference to the problems encountered.

In the OnLoginSuccess event, we simply create a Party Network:

PlayFabMultiplayerManager.Get().CreateAndJoinNetwork();

We then wait for the OnNetworkJoined event and continue from there.

When the game is finished or if an error occurs or the game is cancelled we do the following:

PlayFabMultiplayerManager.Get().LeaveNetwork();PlayFabMultiplayerAPI.CancelMatchmakingTicket(
  new CancelMatchmakingTicketRequest
  {
    QueueName = MatchmakingQueue,
    TicketId = matchmakingTicketId,
  },
  this.OnMatchmakingTicketCancelled,
  this.OnMatchmakingError);

In normal situations this works fine, the user can play many games they can cancel or let the game complete. Disconnections also work (we use our cancel logic above in response to OnRemotePlayerLeft).

However, if there is any kind of network issue, then we we restart the whole process... the call to CreateAndJoinNetwork will never call either the success or failure callback. And most times we get OnError event with the error codes mentioned in the first post.

It can also be reproduced by starting the game with no network connection. If you then plug cable in, the problem will occur on the very first attempt.

It seems to be related to login state, or something not being appropriately reset. But we can't find any documenation or other methods we should call in the lifecycle. So any advice greatly appreciated.

Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Citrus Yan ♦ · Nov 26, 2020 at 10:02 AM 0
Share

Hi Matthew,

I was able to reproduce error 4098, please allow me to investigate further before giving you a proper advice.

avatar image Citrus Yan ♦ Citrus Yan ♦ · Nov 26, 2020 at 10:08 AM 0
Share

Regard error 4330, I was not able to reproduce it, are you still seeing this?

avatar image

Answer by Matthew Tighe · Nov 27, 2020 at 01:37 AM

Hi Citrus,

We were still seeing 4330 (and actually several other errors), it appears to be due to some errors marshalling objects between the native DLL and the CS layer.

There are also several places in the state machine where it will just hang in certain circumstances particularly around login after network connection if that app was booted without.

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Citrus Yan ♦ · Nov 27, 2020 at 09:09 AM 0
Share

Here is what I tried: change PlayFabMultiplayerManager's State to Initialized when network's down, by doing this, error 4098 won't occur, here is the code snippet I used, you can have a try:

    float elapsed = 0f;
    bool stateSet = false;
    void Update()
    {
        elapsed += Time.deltaTime;
        if (elapsed >= 3f) //check network every 3 secs
        {
            elapsed = elapsed % 3f;
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                Debug.Log("Error. Check internet connection!");


                if (PlayFabClientAPI.IsClientLoggedIn() && stateSet == false)
                {
                    stateSet = true;
                    PlayFabMultiplayerManager.Get()._SetPlayFabMultiplayerManagerInternalState(PlayFabMultiplayerManager._InternalPlayFabMultiplayerManagerState.Initialized);
                }
            }
        }
    }

avatar image

Answer by Matthew Tighe · Nov 27, 2020 at 10:42 PM

Thanks Citrus,

We arrived at something similar, resetting the state before each session we created. We seem to have addressed most issues - though there were many places we had to tweak the PlayFabMultiplayerManager state machine for different edge cases.

The remaining issue is that we often get strange errors marshalling objects between the native and cs layer. It seems to be related to the region list.

In the state PARTY_CREATE_NEW_NETWORK_COMPLETED_STATE_CHANGE

The region list often seems to be corrupted or to fail, this causes bad data to go into this line:

this.regions = Converters.PtrToClassArray<PARTY_REGION, Interop.PARTY_REGION>(
  stateChangeConverted.regions,
  regionCount,
  (x) => new PARTY_REGION(x));

Which then causes an Overflow of OutOfMemory exception in PtrToClassArray because the count is a huge invalid number:

ClassType[] ret = new ClassType[(Int32)count];

For now I am checking the count and protecting against this, but it seems there is a deeper issue here.

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Citrus Yan ♦ · Dec 01, 2020 at 09:24 AM 0
Share

Unfortunately, I was not able to reproduce those "strange" errors you mentioned above, may I have more details about them and possibly some steps to reproduce them?

avatar image

Answer by Matthew Tighe · Dec 01, 2020 at 09:47 AM

Hi Citrus,

Those errors happen on every network connection if you use the XBL login provider. I discovered that region data is always just totally corrupt. Once in a while I get an error saying the region data could not be retrieved (especially after a network disconnect).

I discovered the region data is not actually used, so I simply remove all of this, the exception and crashes go away.

Comment

People who like this

0 Show 3 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Citrus Yan ♦ · Dec 01, 2020 at 09:57 AM 0
Share

So it might relate to the XBL SDK you're using, for that I'd suggest you open a thread in the XBOX forum for professional helps:)

avatar image Matthew Tighe Citrus Yan ♦ · Dec 01, 2020 at 11:30 AM 0
Share

Sorry, do you mean a Playfab specific Xbox forum (if so where do I find that). Or the standard Xbox forums (not sure how this would help as it's certainly a Playfab issue)?

avatar image Citrus Yan ♦ Matthew Tighe · Dec 02, 2020 at 02:50 AM 0
Share

Yes, I meant the Xbox Developer forum. Since you're using Party with XBOX GDK, you'd get more professional helps from there.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    Missing PlayFab assembly reference. 1 Answer

    PlayFabServerAPI.GetUserData returning 500 internal error, is playfab down ? 1 Answer

    Uninstalls playfab sdk from unity 1 Answer

    Having trouble with getting invalid input parameters error when calling UpdateUserData. 1 Answer

    I'm making a payment system using XSolla and playfab in unity, to get started, I have to use which facility? Pay Station or Store? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges