Hello, I just started using the new Unity UI.
I made an Input field that clears itself when I hit enter, but it deselects itself. Do you know how can I keep it selected when I hit enter?
I tried using the Select function right after it gets deselected, but it doesn’t work.
Thank you.
Edit: I can’t show code because it isn’t a code related question. I just want to know if there is a way to not stop editing the text on an input field when I press the enter key.
I attached the following script to the InputField:
using UnityEngine;
using UnityEngine.UI;
public class InputFieldController : MonoBehaviour
{
public void KeepActive()
{
GetComponent<InputField>().ActivateInputField();
}
void Start()
{
KeepActive();
}
}
And then I attached KeepActive as an End Edit event in the Input Field component editor.
Another simple solution, just put this in whatever function your InputField executes, at the end.
inputFieldName.ActivateInputField();
inputFieldName.Select();
After your function executes, it will reselect the InputField allowing you to just continue typing and entering.
I found a work around. When I hit Return I select another UI element and then I select the Input field again in the same frame.