- Home /
Programmatically give focus to InputField
Hi. I am looking for a solution on how to give focus to an InputField in the new UI system. I came across this:
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
EventSystem.current.SetSelectedGameObject(input.gameObject, null);
input.OnPointerClick(null);
}
}
The problem is that I get a NullReferenceException on line 6. Others have succesfully used this solution so I would appreciate any help as to why this is not working for me.
Answer by giano574 · Oct 15, 2014 at 07:49 PM
Kesh found a solution which he posted in the Developer Preview forum:
EventSystem.current.SetSelectedGameObject(inputField.gameObject, null);
inputField.OnPointerClick(new PointerEventData(EventSystem.current));
http://forum.unity3d.com/threads/focus-on-inputfield-programmatically.264472/#post-1801779
Your answer
Follow this Question
Related Questions
How to make floating mobile keyboard in mobile game ? 0 Answers
Keep InputField focus / selected when clicking a button / touch screen /UI 4.6 2 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
How to prevent keyboard from showing in Android. 1 Answer
Defocus input line? 0 Answers