FormatException: Input string was not in the correct format - headache

Hi folks,

I’m getting an error when I run my code, its not game breaking but its annoying and I can’t figure out why its happening.
I’m getting a “FormatException: Input string was not in the correct format” for the last line of the following code. I get what the error means, but the string its trying to convert to int IS a number. Anyone got any ideas?

private void LootWindow(int id) {
    if(GUI.Button (new Rect(lootWindowRect.width - 30,0, closeButtonWidth,closeButtonHeight), "x")){
        ClearWindow();
    }
    lootWindowSlider = GUI.BeginScrollView(new Rect(5, 15, lootWindowRect.width - 10, 70),lootWindowSlider,new Rect(0,0,lootItems.Count * buttonWidth, 5 * offset));

    for(int cnt = 0; cnt < lootItems.Count; cnt++){

    if(GUI.Button(new Rect(buttonWidth * cnt, 5, buttonWidth, buttonHeight), new GUIContent (lootItems[cnt].texture, lootItems[cnt].ID.ToString()))){
        playerObject.GetComponent<Player>().inventory.Add(lootItems[cnt]);
        lootItems.Remove(lootItems[cnt]);
    }

    theTooltip = GUI.tooltip;
    Debug.Log (theTooltip);

    }
    DisplayFloatingTooltip();
    GUI.EndScrollView();
}
private void DisplayFloatingTooltip() {
    GameObject itemManager = GameObject.FindGameObjectWithTag("ItemManager");
    curItem = int.Parse(theTooltip);

To clarify, the ID in “lootItems[cnt].ID.ToString()” range from 0 to 6 at the moment.

Any help would be great.

Use this Debug.Log inside DisplayFloatingTooltip right before your int.Parse:

Debug.Log (" >" + theTooltip + "< Length: " + theTooltip.Length);

and you should be able to figure out what’s wrong. Maybe there’s an additional space character in there.