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

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.

        await AuthenticationService.Instance.SignInAnonymouslyAsync();
        // AuthenticationService.Instance.PlayerId = VxMVX...
        var itemsAnon = await Economy.PlayerInventory.GetInventoryAsync();
        AuthenticationService.Instance.SignOut();
        AuthenticationService.Instance.ClearSessionToken();
        await AuthenticationService.Instance.SignInWithAppleAsync(creds.IdToken);
        // AuthenticationService.Instance.PlayerId now correctly = sjNfr...
       
        var itemsApple = await Economy.PlayerInventory.GetInventoryAsync();

        // EXCEPTION OCCURS HERE
        // EconomyException: Player could not be found

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?

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

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.

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.

Yes! That was it. I was on pre.7. Just updated to pre.8 and problem is fixed! Thanks!!

1 Like

That’s excellent news, thanks for letting us know :slight_smile: