Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

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

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

  1. shirtface


    Sep 12, 2014

    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;
    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?