question

Jan Vacek avatar image
Jan Vacek asked

Wait for callback the bast way

Hello,

in my game, Im using GameManager across the whole app. I want to store UserAccountInfo into property of GameManager Singleton and then be able to get the value whenever I need and If it does not exist, create it.

this is what i have, I get everytime cycled in while loop and the game shuts down (at this moment, pretend I have everytime connection to the internet and prefab api, this is my next point, prevent looping while the connection is lost)

what do you mean?

        private UserAccountInfo _userAccountInfo;

        public UserAccountInfo UserAccountInfo
        {
            get {
                    
                if (!PlayfabManager.Instance.IsClientLoggedIn()) {
                    PlayFabLogin();
                    while (_userAccountInfo == null) { }
                }
                
                return _userAccountInfo;
            }
            set => _userAccountInfo = value;
        }


	private void PlayFabLogin()
        {
            PlayfabManager.Instance.LoginWithAndroidId(loginResult => {
                PlayfabManager.Instance.GetAccountInfo(accountInfoResult => {
                    UserAccountInfo = accountInfoResult.AccountInfo;
                });
            });
        }



Player Dataunity3d
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.

Seth Du avatar image Seth Du ♦ commented ·

May I ask how do you define the singleton? We still need more information for troubleshooting. Can you export any logs when your game shuts down?

Besides, you may also ask in C# developer community because usually PlayFab API usage won't cause game shutting down.

0 Likes 0 ·

1 Answer

·
Jan Vacek avatar image
Jan Vacek answered

I've solved it by using callbacks after callbacks from PlayFab

10 |1200

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

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.