question

konstantintodorovic20 avatar image
konstantintodorovic20 asked

App crashes on "OnCharactersDataRecieved",App crashes on OnCharactersDataRecieved

When I export my game as an apk file, open it on my android phone and login, the loading screen is visible, but then suddenly the entire app crashes. So I assume it has something to do with "OnCharactersDataRecieved". And btw. I'm using unity version 2021.3.16f1, targeting API level 31 and use gradle verision 6.9.1, if this is helpfull.

using System.Collections.Generic; using UnityEngine.UI; using UnityEngine; using PlayFab; using PlayFab.ClientModels; using Newtonsoft.Json;

public class PlayFabManager : MonoBehaviour { public CharacterBox[] characterBoxes;

 public ShopManager SM;

 public Levels lvl;

 [Header("Strings")]
 public string name;
 public string mainMenuLevel;

 [Header("Bools")]
 private bool isMuted;

 [Header("Intengers")]
 public int LoggedIN;
 public int LIC;

 [Header("Button")]
 public Button loginButton;
 public Button Afterloginbutton;

 [Header("Windows")]
 public GameObject nameWindow;
 public GameObject leaderboardWindow;
 public GameObject loginWindow;
 public GameObject ErrorWindow;
 public GameObject ErrorWindow_2;
 public GameObject LoadingWindow;

 [Header("Display name window")]
 public InputField nameInput;

 [Header("Leaderboard")]
 public GameObject rowPrefab;
 public Transform rowsParent;

 [Header("UI")]
 public Text messageText;
 public Text messageText_2;
 public InputField emailInput;
 public InputField passwordInput;
 public Text usernameText;

 // Start is called before the first frame update
 void Start()
 {
     loginWindow.SetActive(true);

     LoggedIN = PlayerPrefs.GetInt("logIN", 1);

     if (LoggedIN == 2)
     {
         emailInput.keyboardType = (TouchScreenKeyboardType)(-1);
         passwordInput.keyboardType = (TouchScreenKeyboardType)(-1);
         getMailPassword();
     }

     LIC = 1;
     PlayerPrefs.SetInt("LIC", LIC);

     SM = GameObject.FindObjectOfType<ShopManager>();

     lvl = GameObject.FindObjectOfType<Levels>();

     if (Application.internetReachability == NetworkReachability.NotReachable)
     {
         ErrorWindow.SetActive(true);
     }
 }

 void Update()
 {
     if (isMuted == true)
     {
         AudioListener.pause = true;
     }

     if (isMuted == false)
     {
         AudioListener.pause = false;
     }

     if (Application.internetReachability == NetworkReachability.NotReachable)
     {
         ErrorWindow.SetActive(true);
         ErrorWindow_2.SetActive(true);
     }

     if (ErrorWindow_2.activeSelf)
     {
         LoadingWindow.SetActive(false);

         emailInput.text = "";
         passwordInput.text = "";
     }

     if (usernameText.text == "")
     {
         if (!ErrorWindow.activeSelf)
         {
             if (!ErrorWindow_2.activeSelf)
             {
                 if (!LoadingWindow.activeSelf)
                 {
                     if (!loginWindow.activeSelf)
                     {
                         nameWindow.SetActive(true);
                     }
                 }
             }
         }
     }
     else
     {
         nameWindow.SetActive(false);
     }
 }

 void OnSuccess(LoginResult result)
 {
     Debug.Log("Successful login/account create!");

     ErrorWindow.SetActive(false);

     LoggedIN = 2;
     PlayerPrefs.SetInt("logIN", LoggedIN);

     LIC = 2;
     PlayerPrefs.SetInt("LIC", LIC);

     GetCharacters();

     saveMailPassword();

     GetAccountInfo();

     loginWindow.SetActive(false);
 }

 public void SendLeaderboard(int score)
 {
     if (LIC == 2)
     {
         if (PlayerPrefs.GetInt("LeaderboardSetting") == 1)
         {
             var request = new UpdatePlayerStatisticsRequest
             {
                 Statistics = new List<StatisticUpdate>
                 {
                     new StatisticUpdate
                     {
                         StatisticName = "PlatformScore",
                         Value = score
                     }
                 }
             };
             PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
         }
     }
 }

 void OnLeaderboardUpdate(UpdatePlayerStatisticsResult result)
 {
     Debug.Log("Successful Leaderboard sent!");
 }

 public void GetLeaderboard()
 {
     if (LIC == 2)
     {
         var request = new GetLeaderboardRequest
         {
             StatisticName = "PlatformScore",
             StartPosition = 0,
             MaxResultsCount = 7
         };
         PlayFabClientAPI.GetLeaderboard(request, OnLeaderboardGet, OnError);
     }
 }

 void OnLeaderboardGet(GetLeaderboardResult result)
 {
     foreach(Transform item in rowsParent)
     {
         Destroy(item.gameObject);
     }

     foreach (var item in result.Leaderboard)
     {
         GameObject newGo = Instantiate(rowPrefab, rowsParent);
         Text[] texts = newGo.GetComponentsInChildren<Text>();
         texts[0].text = (item.Position + 1).ToString();
         texts[1].text = item.DisplayName;
         texts[2].text = item.StatValue.ToString();

         Debug.Log(item.Position + " " + item.PlayFabId + " " + item.StatValue);
     }
 }

 void OnDataSend(UpdateUserDataResult result)
 {
     Debug.Log("Successful User Data Send!");
 }

 public void SubmitNameButton()
 {
     if (nameInput.text.Length > 10)
     {
         messageText_2.text = "Username Too Long!";
         return;
     }

     var request = new UpdateUserTitleDisplayNameRequest
     {
         DisplayName = nameInput.text,
     };
     PlayFabClientAPI.UpdateUserTitleDisplayName(request, OnDisplayNameUpdate, OnError);
 }

 void OnDisplayNameUpdate(UpdateUserTitleDisplayNameResult result)
 {
     Debug.Log("Updated Display Name!");
     GetAccountInfo();
 }

 public void RegisterButton()
 {
     if (passwordInput.text.Length < 6)
     {
         messageText.text = "Password Too Short!";
         return;
     }

     var request = new RegisterPlayFabUserRequest
     {
         Email = emailInput.text,
         Password = passwordInput.text,
         RequireBothUsernameAndEmail = false
     };
     PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterSuccess, OnRegisterError);

     if (!ErrorWindow_2.activeSelf)
     {
         loginWindow.SetActive(false);
         LoadingWindow.SetActive(true);
     }
 }

 void OnRegisterSuccess(RegisterPlayFabUserResult result)
 {
     Debug.Log("Registered and logged in!");
     loginWindow.SetActive(false);

     LIC = 2;
     PlayerPrefs.SetInt("LIC", LIC);

     SM.SetDefault();
     lvl.SetLVLN();
     lvl.SetXPN();

     saveMailPassword();
     SaveCharacters();

     GetCharacters();

     GetAccountInfo();

     LoggedIN = 2;
     PlayerPrefs.SetInt("logIN", LoggedIN);

     LoadingWindow.SetActive(false);
 }

 public void LoginButton()
 {
     var request = new LoginWithEmailAddressRequest
     {
         Email = emailInput.text,
         Password = passwordInput.text
     };
     PlayFabClientAPI.LoginWithEmailAddress(request, OnSuccess, OnLogInError);

     if (!ErrorWindow_2.activeSelf)
     {
         loginWindow.SetActive(false);
         LoadingWindow.SetActive(true);
     }
 }

 /*
 public void ResetPasswordButton()
 {
     var request = new SendAccountRecoveryEmailRequest
     {
         Email = emailInput.text,
         TitleId = "5D81B"
     };
     PlayFabClientAPI.SendAccountRecoveryEmail(request, OnPasswordReset, OnError);

     if (!ErrorWindow_2.activeSelf)
     {
         loginWindow.SetActive(false);
         LoadingWindow.SetActive(true);
     }
 }

 void OnPasswordReset(SendAccountRecoveryEmailResult result)
 {
     // Nothing XD
 }

 */

 public void SaveCharacters()
 {
     List<Character> characters = new List<Character>();
     foreach (var item in characterBoxes)
     {
         characters.Add(item.ReturnClass());
     }

     var request = new UpdateUserDataRequest
     {
         Data = new Dictionary<string, string>
         {
             {"Characters", Newtonsoft.Json.JsonConvert.SerializeObject(characters) }
         }
     };
     PlayFabClientAPI.UpdateUserData(request, OnDataSend, OnError);
 }

 public void GetCharacters()
 {
     PlayFabClientAPI.GetUserData(new GetUserDataRequest(), OnCharactersDataRecieved, OnError);
 }

 void OnCharactersDataRecieved(GetUserDataResult result)
 {
     Debug.Log("Recieved Characters Data!");

     if(result.Data != null && result.Data.ContainsKey("Characters"))
     {
         List<Character> characters = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Character>>(result.Data["Characters"].Value);
         for (int i = 0;i < characterBoxes.Length;i++)
         {
             characterBoxes[i].SetUi(characters[i]);
         }

         LoadingWindow.SetActive(false);

         if(PlayerPrefs.GetInt("SetLogged") == 0)
         {
             PlayerPrefs.SetInt("SetLogged", 2);
         }
     }
 }

 void GetUsername(GetPlayerProfileResult result)
 {
     usernameText.text = result.PlayerProfile.DisplayName;
 }

 public void GetAccountInfo()
 {
     var request = new GetPlayerProfileRequest
     {
         ProfileConstraints = new PlayerProfileViewConstraints()
         {
             ShowDisplayName = true
         }
     };
     PlayFabClientAPI.GetPlayerProfile(request, GetUsername, OnError);
 }

 public void saveMailPassword()  // Probleme!
 {
     PlayerPrefs.SetString("mailget", emailInput.text);
     PlayerPrefs.SetString("passwordget", passwordInput.text);

     PlayerPrefs.GetString("mailget", emailInput.text);
     PlayerPrefs.GetString("passwordget", passwordInput.text);
 }

 public void getMailPassword()   // Probleme!
 {
     emailInput.text = PlayerPrefs.GetString("mailget");
     passwordInput.text = PlayerPrefs.GetString("passwordget");
     loginButton.onClick.Invoke();
 }

 public void LogOut()
 {
     LIC = 1;
     PlayerPrefs.SetInt("LIC", LIC);

     LoggedIN = 1;
     PlayerPrefs.SetInt("logIN", LoggedIN);
     Application.LoadLevel(mainMenuLevel);
 }

 public void LoadMain()
 {
     Application.LoadLevel(mainMenuLevel);
 }

 public void GetSaveCharacters()
 {
     SaveCharacters();
 }

 public void SaveandgetCH()
 {
     SaveCharacters();
     GetCharacters();
 }

 void OnError(PlayFabError error)
 {
     ErrorWindow_2.SetActive(true);
     loginWindow.SetActive(true);
     Debug.Log("Error while logging in/creating account!");
     Debug.Log(error.GenerateErrorReport());
 }

 void OnLogInError(PlayFabError error)
 {
     ErrorWindow_2.SetActive(true);
     loginWindow.SetActive(true);
     Debug.Log("Error while logging in/creating account!");
 }

 void OnRegisterError(PlayFabError error)
 {
     ErrorWindow_2.SetActive(true);
     loginWindow.SetActive(true);
     nameWindow.SetActive(false);
     Debug.Log("Error while logging in/creating account!");
 }

}

5421-api-playfab.png

I've sat so long, but still haven't found any solution.

Any ideas?

Thanks!!

-Konstantin

Player Dataapissdks
api-playfab.png (69.6 KiB)
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.

Neils Shi avatar image Neils Shi commented ·

Can you tell me if any error is reported when running in Unity's Editor mode? You can provide us with crash logs so that we can conduct further research.

0 Likes 0 ·

0 Answers

·

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.