Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved "Player could not be found" error if switching from Anonymous to Apple account

Discussion in 'Economy' started by mhardy, Feb 4, 2022.

  1. mhardy

    mhardy

    Joined:
    Apr 3, 2011
    Posts:
    48
    I'm not sure if this is an Authentication or Economy issue but posting here as Economy is what's throwing the exception.

    I'm trying to work out the sequence when a user switches from an Anonymous account to an Apple account that they have already signed in to on another device. After signing out from the Anonymous account and signing in with the Apple account, Economy no longer works.

    Here's the code I'm using to test.

    Code (CSharp):
    1.  
    2.  
    3.         await AuthenticationService.Instance.SignInAnonymouslyAsync();
    4.         // AuthenticationService.Instance.PlayerId = VxMVX...
    5.         var itemsAnon = await Economy.PlayerInventory.GetInventoryAsync();
    6.         AuthenticationService.Instance.SignOut();
    7.         AuthenticationService.Instance.ClearSessionToken();
    8.         await AuthenticationService.Instance.SignInWithAppleAsync(creds.IdToken);
    9.         // AuthenticationService.Instance.PlayerId now correctly = sjNfr...
    10.        
    11.         var itemsApple = await Economy.PlayerInventory.GetInventoryAsync();
    12.  
    13.         // EXCEPTION OCCURS HERE
    14.         // EconomyException: Player could not be found
    15.  
    16.  
    17.  
    I know for certain the player exists and I can look them up. And the AuthenticationService.Instance.PlayerId is set correctly after the SignIn calls. What am I missing?
     
  2. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    Hi there,

    Thanks for sharing your problem and code snippet.

    Can you clarify your use case?

    Are you testing that the stored economy currencies and inventory state created on device #1 whilst signed in to Apple, can be retrieved on device #2 when the player switches from anonymous authentication to Apple authentication using the same credentials as device#1?

    Please let me know if this is not the case. In the meantime I will investigate and get back to you.

    regards,
    Laurie
     
  3. mhardy

    mhardy

    Joined:
    Apr 3, 2011
    Posts:
    48
    Yes, that is preciously what I'm doing.

    And note, this only happens during the session when the user signs in with apple the first time on the new device and their PlayerId gets updated to their linked account. If I restart the app, now that their PlayerId is the correct one (sjNfr in this example), and I only SignInAnonymously, economy works just fine.

    The problem only occurs after the SignOut / SignInWithApple sequence.

    Thanks.
     
    Last edited: Feb 6, 2022
  4. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    Thanks for confirming the use case.

    We believe you may have run into a known bug that has recently been fixed. There was an update to the Economy SDK on 20th Jan to v1.0.0-pre.8, it sounds suspicioulsy like what you've run into.

    Can you confirm what versions you are using, particularly for the Economy SDK.
    Feel free to paste the relevant section from your
    Packages/manifest.json
    file for us to confirm.
     
  5. mhardy

    mhardy

    Joined:
    Apr 3, 2011
    Posts:
    48
    Yes! That was it. I was on pre.7. Just updated to pre.8 and problem is fixed! Thanks!!
     
    Laurie-Unity likes this.
  6. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    That's excellent news, thanks for letting us know :)