issues with unity and firebase, some accounts cant run under dbPlayerRef.Child(uuid).GetValueAsync().ContinueWithOnMainThread(task =>

im making a game using firebase and unity, where players log in, and for them to play a clicker game, once the timer is up on the clicker game, it will call this function where the highscore is stored in firebase. If there is no existing data, under the keys leaderboard and playerStats, it will create a key of uuid and under the key is the display name used when registering and the score 0.

The issue is it works half the time, where for some users the function mentioned earlier works, but other times it does not even create the data at all under leaderboard or playerStats, when debuging, the debug stops at Debug.Log(uuid), meaning it doesnt pass under the GetValueAsync, and it doesnt debug log the error message as well

   public void UpdatePlayerStats(string uuid, int score, string displayName)
   {
       
       Query playerQuery = dbPlayerRef.Child(uuid);
       Debug.Log("CHILD");
       Debug.Log(uuid);

       dbPlayerRef.Child(uuid).GetValueAsync().ContinueWithOnMainThread(task =>
       {
           if (task.IsCanceled || task.IsFaulted)
           {
               Debug.Log("error in saving playerStatLeaderboarddata");
               return;
           }
           else if (task.IsCompleted)
           {
               Debug.Log(uuid+"before datasnapshot");
               DataSnapshot playerStats = task.Result;
               Debug.Log(uuid + "after datasnapshot");
               if (playerStats.Exists)
               {
                   Debug.Log("exits???");
                   //updates if there is someting
                   SimplePlayerStat sp = JsonUtility.FromJson<SimplePlayerStat>(playerStats.GetRawJsonValue());
                   Debug.Log("scoreeee");
                   if( score > sp.score )
                   {
                       sp.score = score;
                       UpdatePlayerLeaderBoard(uuid, sp.score);
                       dbPlayerRef.Child(uuid).Child("score").SetValueAsync(score);
                       Debug.Log("helloooooo");
                       
                   }
                   dbPlayerRef.Child(uuid).SetPriorityAsync(sp.SimplePlayerStatsToJson());
               }
               else
               {
                   Debug.Log("newww");
                   //creates new stats if there is no player inside
                   SimplePlayerStat sp = new SimplePlayerStat(displayName, score);
                   SimpleLeaderBoard lb = new SimpleLeaderBoard(displayName, score);//(displayName, score);

                   dbPlayerRef.Child(uuid).SetRawJsonValueAsync(sp.SimplePlayerStatsToJson());
                   dbLeaderboardRef.Child(uuid).SetRawJsonValueAsync(lb.SimpleLeaderBoardToJson());
               }
           }
       });
   }

my teacher has suggested maybe their a bad user? but he doesnt know how to fix this issue as well, i really need the helpthe image here shows how it should look like if successful, playerstats looks the same as well

Leave a Comment