Parse issue, despite the data being pulled from database

Hello all!

I am in need of some help, for the past two or three days I have been pulling my hair out on a parse issue.

To give you a quick run down, I am trying to work on a Rank system. Basically, the game connects to a database, gets the data so that I can set the rank image based off of how much XP a player has. I.E if the player has over 1000XP but less than 2000 he will be at rank 3 for example. The data in the database is text. I am trying to convert it to a int.

I can get and set the data no problem, the connection works and I can see the value in the inputfield text when I pause the game. So I know its working. However, I keep getting this error: “FormatException: Input string was not in the correct format System.Int32.Parse” we all know how it ends. I even added a debug.log and it isn’t helping me at all. I have tried so many variations of code from my several days of googling. I found a lot of topics about this issue, but nothing exactly as to what I am facing. I have checked the text of the inputfield and there are no crazy characters or spaces or unknown variables.

Please excuse the mess, I am not the best coder, and I have gone through so many variations just to try and get it to work, before I can clean it up.

 void OnJoinedLobby()
        Debug.Log("We joined the lobby.");
        ChangeWindow(2, 1);
        // getrank();

        //Data 1 i s XP for now 

        //  int xpdata2 = Int.
        // if (xpdata2 > 1)
        // {
        //     PlayerRank.SetRank1();

        //  }

        // GetFromServer.Data1.text = RANKSXP.ToString();
        // GetFromServer.Data2.text = RANKSXP.ToString();
        // GetFromServer.Data3.text = RANKSXP.ToString();
    public static Image Rank1;
    private static LoginPro_GetFromServer GetFromServer;
    public static void getrank()
        // Rank1 = GameObject.FindWithTag("RankImage").GetComponent<RawImage>();
        Rank1 = GameObject.FindWithTag("RankImage").GetComponent<Image>();
        GetFromServer = GameObject.FindWithTag("RanksTagGet").GetComponent<LoginPro_GetFromServer>();
        string ranktest = GetFromServer.Data1.text.ToString();

          int xpdata2 = int.Parse(GetFromServer.Data1.text);
          if (xpdata2 >= 100)
                Rank1.sprite = Resources.Load<Sprite>("Bronze0") as Sprite;

            Debug.Log(">" + GetFromServer.Data1.text + "Ranktest: " + ranktest.Length);
        //int xpdata2 = int.Parse(GetFromServer.Data1.text);


Please also excuse some of the commented failure tests. Its supposed to set the image based on the XP value given from the database. I have also made sure to set the inputfield as integer number. I have tried both. I have even tried custom. I have tried TryParse. Any help would be appreciated. Thank you guys so much!

I am sorry I had to ask a question at all, but I am really lost.

seems your GetFromServer.Data1.text is empty already, check your GetFromServer.GetFromServer(); function or post code to get the help

@Bilelmnasser You were correct. It appears as though the method isn’t giving it any time to grab the data. I thought I had moved the getrank method somewhere else to give it time but did not work. I tried again and moved it to a different spot and it seems to work. I can pull data all day long now. I use that method at a different point on a different script (not rank related) and I have run into the same issue.

I looked into commands that would delay the function from moving forward but I have had no luck. It seems to steamroll right past it. Do you know of a quick way to sort of pause the method until it has retrieved the data?

Again I really appreciate everything.