- Home /
New UI system. How to focus on input fields.
I'm checking out the new unity 4.6.0b17. It's very similar to NGUI to use.
I'm using input fields and can't figure out how to focus on a targeted input field if I click on some label anywhere on the screen which is meant to focus the targeted input field on click. I can't seem to find any such method in the method drop down list for input fields (I'm using the event trigger component).
Any help would be appreciated. Thanks in advance.
As 4.6 is currently Beta, the chances of getting a good answer on this are $$anonymous$$imal. It can be hard to tell intended functionality vs bugs.
You can get it to visually focus by calling its OnPointerClick() method, but it doesn't appear to begin editing.
Did you figure it out? I am looking for an answer as well.
Answer by Tryz · Dec 17, 2014 at 04:06 PM
You also may need to activate it for the cursor to show up:
lInputField.Select();
lInputField.ActivateInputField();
I just logged in to upvote your post. This was the simple answer that was required and I read all sorts of complex suggestion everywhere else.
The perfect and simple solution that still works years later!
Answer by pritambarhate · Dec 14, 2014 at 08:56 AM
After spending about an hour on this, for me, following seems to work:
nameField.Select();
Answer by Mr-Slat · May 30, 2015 at 04:30 PM
be careful not to use Select() or ActivateInputField() inside awake methods.... if so change them to Start.
Answer by Kaz_Yamof · Nov 15, 2014 at 02:19 AM
Hi guys!
I was looking for that too, and I made this to get the visual focus and start typing on Unity 4.6b20:
EventSystem.current.SetSelectedGameObject(myInputField.gameObject, null);
myInputField.OnPointerClick(new PointerEventData(EventSystem.current));
I passed null to the BaseEventData parameter on SetSelectedGameObject, and I called the OnPointerClick by sending a new PointerEventData of the current event system.
Answer by Hassanshin · Jul 09, 2019 at 09:09 AM
NEVER DO THIS
Input.Field.gameobject.setActive(false);
try to disable the Image component, or change the alpha to 0