question

omegareaperxza avatar image
omegareaperxza asked

PlayFabLogin works. But only sometimes.,My PlayFabLogin script only sometimes works. Half the time the special items and currency don't load.

I've been working on this gorilla tag fan game for a few weeks now, but I keep seeing this bug that I can't find a fix for. I have a system where certain people get special items (mod stuff, cosmetics, etc.) but PlayFabLogin only sometimes works. For example: I might playtest the game one time and the mod stuff won't load. But the next time it works just fine. Or, I would load into the game and have my mod stuff, but my friend (whom I gave mod to) doesn't have his stuff. There are no errors or warnings in the console, and there are no (from what I see) errors in the code. If it helps, here is the code I'm using: using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using System.Threading.Tasks; using PlayFab.ClientModels; using UnityEngine.SceneManagement; using TMPro;

public class Playfablogin : MonoBehaviour { [Header("COSMETICS")] public static Playfablogin instance; public string MyPlayFabID; public string CatalogName; public List specialitems; public List disableitems; [Header("CURRENCY")] public string CurrencyName; public TextMeshPro currencyText; [SerializeField] public int coins; [Header("BANNED")] public string bannedscenename; [Header("TITLE DATA")] public TextMeshPro MOTDText; [Header("PLAYER DATA")] public TextMeshPro UserName; public string StartingUsername; public string name; [SerializeField] public bool UpdateName;

 public void Awake()
 {
     instance = this;
 }

 void Start()
 {
     login();
        
 }

 public void login()
 {

     var request = new LoginWithCustomIDRequest
     {
         CustomId = SystemInfo.deviceUniqueIdentifier,
         CreateAccount = true,
         InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
         {
             GetPlayerProfile = true
         }
     };
     PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnError);
 }

 public void OnLoginSuccess(LoginResult result)
 {
     Debug.Log("logging in");
     GetAccountInfoRequest InfoRequest = new GetAccountInfoRequest();
     PlayFabClientAPI.GetAccountInfo(InfoRequest, AccountInfoSuccess, OnError);
     GetVirtualCurrencies();
     GetMOTD();
 }

 public void AccountInfoSuccess(GetAccountInfoResult result)
 {
     MyPlayFabID = result.AccountInfo.PlayFabId;

     PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(),
     (result) =>
     {
         foreach (var item in result.Inventory)
         {
             if (item.CatalogVersion == CatalogName)
             {
                 for (int i = 0; i < specialitems.Count; i++)
                 {
                     if (specialitems[i].name == item.ItemId)
                     {
                         specialitems[i].SetActive(true);
                     }
                 }
                 for (int i = 0; i < disableitems.Count; i++)
                 {
                     if (disableitems[i].name == item.ItemId)
                     {
                         disableitems[i].SetActive(false);
                     }
                 }
             }
         }
     },
     (error) =>
     {
         Debug.LogError(error.GenerateErrorReport());
     });
 }

 async void Update()
 { 
 }

 public void GetVirtualCurrencies()
 {
     PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), OnGetUserInventorySuccess, OnError);
 }

 void OnGetUserInventorySuccess(GetUserInventoryResult result)
 {
     coins = result.VirtualCurrency["HS"];
     currencyText.text = "You have " + coins.ToString() + " " + CurrencyName;
 }

 private void OnError(PlayFabError error)
 {
     if (error.Error == PlayFabErrorCode.AccountBanned)
     {
         SceneManager.LoadScene(bannedscenename);
     }

 }
 //Get TitleData

 public void GetMOTD()
 {
     PlayFabClientAPI.GetTitleData(new GetTitleDataRequest(), MOTDGot, OnError);
 }

 public void MOTDGot(GetTitleDataResult result)
 {
     if (result.Data == null || result.Data.ContainsKey("MOTD") == false)
     {
         Debug.Log("No MOTD");
         return;
     }
     MOTDText.text = result.Data["MOTD"];
        
 }

} If anyone could find a potential solution it would be GREATLY appreciated. I've had this issue since the start of making this game and I can't find a fix. Thank you.,this is the script i am using: using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using System.Threading.Tasks; using PlayFab.ClientModels; using UnityEngine.SceneManagement; using TMPro;

public class Playfablogin : MonoBehaviour { [Header("COSMETICS")] public static Playfablogin instance; public string MyPlayFabID; public string CatalogName; public List specialitems; public List disableitems; [Header("CURRENCY")] public string CurrencyName; public TextMeshPro currencyText; [SerializeField] public int coins; [Header("BANNED")] public string bannedscenename; [Header("TITLE DATA")] public TextMeshPro MOTDText; [Header("PLAYER DATA")] public TextMeshPro UserName; public string StartingUsername; public string name; [SerializeField] public bool UpdateName;

 public void Awake()
 {
     instance = this;
 }

 void Start()
 {
     login();
        
 }

 public void login()
 {

     var request = new LoginWithCustomIDRequest
     {
         CustomId = SystemInfo.deviceUniqueIdentifier,
         CreateAccount = true,
         InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
         {
             GetPlayerProfile = true
         }
     };
     PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnError);
 }

 public void OnLoginSuccess(LoginResult result)
 {
     Debug.Log("logging in");
     GetAccountInfoRequest InfoRequest = new GetAccountInfoRequest();
     PlayFabClientAPI.GetAccountInfo(InfoRequest, AccountInfoSuccess, OnError);
     GetVirtualCurrencies();
     GetMOTD();
 }

 public void AccountInfoSuccess(GetAccountInfoResult result)
 {
     MyPlayFabID = result.AccountInfo.PlayFabId;

     PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(),
     (result) =>
     {
         foreach (var item in result.Inventory)
         {
             if (item.CatalogVersion == CatalogName)
             {
                 for (int i = 0; i < specialitems.Count; i++)
                 {
                     if (specialitems[i].name == item.ItemId)
                     {
                         specialitems[i].SetActive(true);
                     }
                 }
                 for (int i = 0; i < disableitems.Count; i++)
                 {
                     if (disableitems[i].name == item.ItemId)
                     {
                         disableitems[i].SetActive(false);
                     }
                 }
             }
         }
     },
     (error) =>
     {
         Debug.LogError(error.GenerateErrorReport());
     });
 }

 async void Update()
 { 
 }

 public void GetVirtualCurrencies()
 {
     PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), OnGetUserInventorySuccess, OnError);
 }

 void OnGetUserInventorySuccess(GetUserInventoryResult result)
 {
     coins = result.VirtualCurrency["HS"];
     currencyText.text = "You have " + coins.ToString() + " " + CurrencyName;
 }

 private void OnError(PlayFabError error)
 {
     if (error.Error == PlayFabErrorCode.AccountBanned)
     {
         SceneManager.LoadScene(bannedscenename);
     }

 }
 //Get TitleData

 public void GetMOTD()
 {
     PlayFabClientAPI.GetTitleData(new GetTitleDataRequest(), MOTDGot, OnError);
 }

 public void MOTDGot(GetTitleDataResult result)
 {
     if (result.Data == null || result.Data.ContainsKey("MOTD") == false)
     {
         Debug.Log("No MOTD");
         return;
     }
     MOTDText.text = result.Data["MOTD"];
        
 }

} I'm making a gorilla tag fan game, and I don't know if other people have this issue. There are no errors or warnings about it. But it's really bugging me and if anyone knows a fix I would greatly appreciate it

Player DataPlayer Inventory
10 |1200

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

1 Answer

·
Neils Shi avatar image
Neils Shi answered

Could you tell us what functionality you would like to achieve? Are you calling the API GetTitleData to retrieve mod info? If so, please note that Title Data values are copied and distributed to potentially hundreds of machines in the PlayFab server cluster. As part of this process, Title Data is cached, and changes may take up to fifteen minutes to refresh in those caches. This might be why the mod stuff didn't load while you were playtesting your game, but it worked fine again after that. In addition, you do not need to call additional API GetAccountInfo/GetUserInventory to retrieve the player's account/virtual currency info. When a player calls the login API to log in, you can specify which pieces of info to return for the user by setting the request parameter "InfoRequestParameters" (https://learn.microsoft.com/en-us/rest/api/playfab/client/authentication/login-with-custom-id?view=playfab-rest#getplayercombinedinforequestparams) .

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.