Search Unity

[Unsolved]Cannot get the next selectable item during compile time

Discussion in 'UGUI & TextMesh Pro' started by shirtface, Aug 15, 2015.

  1. shirtface

    shirtface

    Joined:
    Sep 12, 2014
    Posts:
    4
    Hello

    I am attempting to insert buttons into a list with this script that runs on Start() Note that the buttons navigation is set to automatic.

    Code (CSharp):
    1. Selectable potentialButton = firstButton;
    2. while (true)
    3.     {
    4.       if (potentialButton == null)
    5.          {
    6.             Debug.Log("button is null");
    7.             break;
    8.          }
    9.       if (IsValidButton(potentialButton))
    10.       {
    11.          TopRow.Add((Button)potentialButton);
    12.          potentialButton = potentialButton.FindSelectableOnRight() as Button;
    13.  
    14.       }
    15.    }
    However it doesn't seem to be adding the buttons properly. Matter of fact, the number of items in the TopRow list seems to be random. However when I run that same command during runtime, I am getting the correct number of elements inserted into the list. This is strange behaviour, how do I go about correcting this?