- Home /
Input field deselecting when I hit enter.
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.
Answer by octavia · Mar 13, 2015 at 06:23 PM
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.
Answer by Invertex · Jun 12, 2016 at 07:16 AM
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.
Answer by el-pepi · Mar 10, 2015 at 12:19 AM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613185635im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Request feedback for C# script (instantiating UI elements depending on Player Input) 0 Answers
Customize Inputfield Unity Plus/Pro 0 Answers
Anyone know why my InputField is not being disabled? 0 Answers
How do I change "return"/"submit" button to "search" in native android keyboard in TMP_InputField? 1 Answer
How to modify EditText appearance on Android and iOS? 0 Answers