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

Question InputField.Select Changing Value?

Discussion in 'UGUI & TextMesh Pro' started by JudahMantell, Sep 2, 2021.

  1. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    I'm trying to make a basic tab navigation system between a set amount of input fields, and for some reason whenever I call
    Select()
    (with or without
    ActivateInputField()
    ), The value of the field changes to 0, then when focus is lifted/changed, it changes to the value of the following field.
    I have tried multiple suggested tab nav systems, and this is happening no matter what.
    Any ideas?

    I have this script on a parent gameObject, and I am setting the
    CurrentSelectableIndex
    to the correct one in a script on the input fields with an ISelectHandler interface.
    Code (CSharp):
    1. EventSystem EventSystem;
    2.         /// <summary>
    3.         /// List of GameObjects that are selectable
    4.         /// </summary>
    5.         public List<GameObject> Selectables;
    6.         /// <summary>
    7.         /// The index of the current selected GameObject
    8.         /// </summary>
    9.         public int CurrentSelectableIndex = 0;
    10.         void Start()
    11.         {
    12.             EventSystem = EventSystem.current;
    13.         }
    14.         void Update()
    15.         {
    16.             if (Input.GetKeyDown(KeyCode.Tab)
    17.                 || Input.GetKeyDown(KeyCode.RightArrow))
    18.             {
    19.                 CurrentSelectableIndex += 1;
    20.                 EventSystem.SetSelectedGameObject(Selectables[CurrentSelectableIndex % Selectables.Count()], new BaseEventData(EventSystem));
    21.             }
    22.             if (Input.GetKeyDown(KeyCode.LeftArrow))
    23.             {
    24.                 CurrentSelectableIndex -= 1;
    25.                 EventSystem.SetSelectedGameObject(Selectables[CurrentSelectableIndex % Selectables.Count()], new BaseEventData(EventSystem));
    26.             }
    27.         }