Search Unity

InputFields automated activation by EventSystem?

Discussion in 'UGUI & TextMesh Pro' started by RagingJacob, Mar 15, 2015.

  1. RagingJacob

    RagingJacob

    Joined:
    Jun 19, 2013
    Posts:
    72
    Edit: Problem has been solved thanks to Simon hinting at a possible mistake.:oops:

    Dear Unity Community

    I've been using Inputfields as of 4.6x and beyond but never have I run into this trouble with the EventSystem.

    What's happening as far as I understand is that the InputFields on screen are being activated before the user even taps on them, which means the focus gets put on the first InputField.

    This is causing half of the screen to be covered with a keyboard on Android, without the user knowing what they're supposed to enter, aesthetically this is not so pleasing.

    I've looked into it and it seems the EventSystem is deciding on what to activate before any action is given to it, but I have no idea on how to disable this behavior to avoid unwanted keyboards to pop up on Android.

    This only started happening after I've upgraded my existing android project from Unity 5 beta to Unity 5.0 release and somehow whenever I enable any part of the Canvas now that has an inputfield this stuff happens.

    Does anyone know how to end this automated stuff by the eventsystem in favor of the user deciding which inputfield to activate ?

    Thanks in advance ! :)
     
    Last edited: Mar 16, 2015
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    It sounds like a bug, so I would log it using the Unity bug reporter.

    One quick solution is to set "Selection.activeGameObject" to a button or other non input field when the UI is launched (from Start, NOT from awake)
    e.g. (from memory!)
    Code (CSharp):
    1. void Start()
    2. {
    3. var startUIObject = GameObject.FindObjectWithTag("StartObject");
    4. Selection.activeGameObject = startUIObject;
    5. }
     
    RagingJacob likes this.
  3. RagingJacob

    RagingJacob

    Joined:
    Jun 19, 2013
    Posts:
    72
    Thank you for your input Simon, but I'm afraid that didn't do much sadly,
    that's just causing the gameObject to be selected in editor. :confused:

    For this app to circumvent automated focus on the InputFields,
    (i.e. avoid putting the cursor in the InputField prematurely )
    I'd need to tell the EventSystem somehow to change selection before anything is awoken ?

    Still think there should be a way to tell the Unity EventSystem to yield until user input :(
    I've tried removing and re-adding the EventSystem to the hierarchy but no success.
    This is a high priority problem for me, I have to find a way around it ASAP.

    Any help is welcome at this point. :oops:
     
    Last edited: Mar 16, 2015
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Yeah, you can't remove the event system. It is the core for user input and events.

    Have you tried the "EventSystem.SetSelectedGameObject" function on awake (should work because EventSystem is a singleton):
    Code (CSharp):
    1.     void Awake () {
    2.         EventSystem.current.SetSelectedGameObject(null);  
    3.     }
    > This was what I was originally thinking of but wasn't near a PC to check :S

    Now one odd thing.
    I started a new project and added several input fields and a button, but when I ran it, nothing was selected by default. So is there something in your scene automatically selecting an inputfield on startup?
     
    RagingJacob likes this.
  5. RagingJacob

    RagingJacob

    Joined:
    Jun 19, 2013
    Posts:
    72
    Final EDIT: Oh my, you were right Simon, I traced it back to a script I wrote months ago and I was indeed altering the currentSelectedGameobject, I can't believe I overlooked it. :oops:
    My sincerest apologies for the confusion, I've left my previous response below but it's irrelevant now! Funny how this was never a problem in the Beta version.


    Nope, there's nothing in the hierarchy selecting the InputField other than the EventSystem itself.
    And I tried doing that SetSelectedGameObject(null) function call On Awake before, but sadly to no avail.

    I even tried calling that function in Update for the first loop through with a boolean and even after setting the selected gameobject to null it jumps back to a random UI element that is enabled in the hierarchy.

    It definitely looks like a bug!
    Everything was fine before, this automatic activation of UI elements only started happening after moving the project from Unity 5 beta to Unity 5.0 release.

    It's as if the SelectedGameObject can't be null at all for the EventSystem
    Another remark, First Selected is also not working in the Inspector for the EventSystem in the Scene!

    Even if I drag in the GameObject of a Toggle for example,
    it jumps back to the first UI Element that is enabled in the Hierarchy
    and sets it as Active (Selected in the EventSystem)

    I mean if it's not an InputField, it's a Button, if not a Button it's a Toggle....

    Quick EDIT:
    These UI Elements are child objects of Empty GameObjects called "Panel" in my Scene Hyrarchy. Could setting the panels active, where these UI elements are on, be causing the EventSystem to select the first UI element in hierarchy and setting those active ? Because I am setting the "Panel" where these UI elements are placed on to active during panel transitions through animation
     
    Last edited: Mar 16, 2015
    SimonDarksideJ likes this.
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Its fine @KillerKahuna we live, we learn, we make mistakes and then more importantly we pick ourselves up.

    Glad you finally managed to nail down the issue :D
     
    RagingJacob likes this.