Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED]I can't use Select() on my Buttons in scripts

Discussion in 'UGUI & TextMesh Pro' started by Thibault-Potier, May 8, 2015.

  1. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206
    Hi
    i'm working on a menu using xbox controller

    I want to select a <Button> object in a script, but get an error i can't solve

    First i made a public list of buttons that i dragged and dropped in the inspector

    Code (CSharp):
    1. public List<Button> ButtonTab;
    2. private int idNav;
    Then later when i tryed to do this :
    Code (CSharp):
    1. ButtonTab [idNav].Select ();
    i got the error :

    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.UI.Selectable.Select () (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Selectable.cs:612)
    MenuController.Update () (at Assets/Script/MenuController.cs:43)

    If you have an idea or if you know a better way to highlight my current button it would be amazing <3
     
  2. Thibault-Potier

    Thibault-Potier

    Joined:
    Apr 10, 2015
    Posts:
    206
    Ok i figured out.

    You know the EventSystem thing which appears when you create a canvas ? well don't delete it >< i had it hiden in a hierarchy that i diseabled and so it couldn't work. I feel stupid. Slap me.
     
    Tangqi, GabCap and SimonDarksideJ like this.
  3. nfcopier

    nfcopier

    Joined:
    Mar 23, 2016
    Posts:
    1
    I've been trying to figure this out for a week now. And finally, you gave me the solution! You're a hero, man!