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

Reselecting InputField

Discussion in 'UGUI & TextMesh Pro' started by JaggerMcClaw, Oct 26, 2014.

  1. JaggerMcClaw

    JaggerMcClaw

    Joined:
    Oct 26, 2014
    Posts:
    2
    I'm making a simple hangman game in 4.6 and I've got pretty much everything done, but the player has to click the InputField in order to type in it, and when they submit, the InputField is deselected. I tried to select the field again using SetSelectedGameObject
    Code (CSharp):
    1. EventSystemManager.currentSystem.SetSelectedGameObject (inputField,null);
    but I get the error
    Argument `#1' cannot convert `UnityEngine.UI.InputField' expression to type `UnityEngine.GameObject'
    I'm assuming this is because most of the new UI elements aren't counted as GameObjects yet.
    Is there a way to make sure the InputField is always selected so the player can type in it, or at least doesn't deselect when the player submits?

    PS, this is the code I'm using for submiting
    Code (CSharp):
    1. inputField.onSubmit.AddListener((value) => SubmitGuess(value)); submitButton.onClick.AddListener(() => SubmitGuess(inputField.value));
    It deselects the InputField in both types of submission.
     
  2. Wenzil

    Wenzil

    Joined:
    Apr 3, 2013
    Posts:
    19
    In b20 and b21 I use:

    Code (CSharp):
    1. inputField.Select();
    2. inputField.ActivateInputField();
     
    JaggerMcClaw likes this.
  3. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    I agree with what Wenzil says but to add to your knowledge here is more info.
    No UI elements will never be counted as GameObjects UI elements are components just like "Light" or "Animation" or "Camera". All components are attached to a GameObject so you can do myComponent.gameObject to get the GameObject for that component.