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?
[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
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).
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.