- Home /
Escape Key reverts text in Input Field
In our game, the user has the possibility to take notes in a journal and save them. He types the text he wants to save in an input field and can then save it by pressing the "save"-button. That works fine, but I wanted to implement an autosave-function, so the text is also saved when the player leaves the journal without saving. However, when the escape key is pressed, the current text in the input field is deleted automatically and there’s nothing I can do about it. I've already read that this seems to be a predefined function of the Escape-button. Does anybody know how I can change that?
Answer by Gillissie · Oct 25, 2020 at 08:28 PM
In case anyone is still having this issue in 2020, here is the solution (I'm using Unity 2018).
Uncheck the "Restore on ESC Key" checkbox on the TMP_InputField properties (under Control Settings).
THIS! Wow, thanks so much for responding. I had no clue what was going on trying to hunt this one down.
Answer by adibichea · May 09, 2017 at 05:19 AM
[SerializeField]
InputField textToSend;
string stringEdit = "";
public void OnEditting()
{
if (!Input.GetKeyDown(KeyCode.Escape))
{
stringEdit = textToSend.text;
}
}
public void OnEndEdit()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
textToSend.text = stringEdit;
}
}
Hope it helps
Answer by Nischo · Feb 22, 2017 at 01:50 PM
You could go for the brute force approach: Create a copy of the InputField.cs. You can find the code for online, change the namespace and remove the Part that handles the Escape. That might not work depending on how many cross references to other code especially internal ones, the InputField has.
Your answer

Follow this Question
Related Questions
Text MeshPro Input field insert integer? 1 Answer
DropDown menu(add item from input field): Object reference not set to instance of an object C# 1 Answer
Making a UI.Button put text into a InputField 1 Answer
InputField limits characters unwantedly, even with no character limit 1 Answer
New gui: How to disable keyboard input when user is typing? 2 Answers