- Home /
Backspace in limited length textfield causes ArgumentOutOfRangeException
Hello everyone,
Tried using GUI.TextField with limited length of 4, but when I type '1234' and type any other number then try using backspace to delete the string, it throws the said error.
ArgumentOutOfRangeException: startIndex + count > this.length
Parameter name: count
Following the stacktrace it seems UnityEngine.TextEditor.Backspace () gets called but the string length already changed and so the error occurs. Tried unsuccessfully to get around it but not luck so far, only by negating the backspace event when it reaches capacity, but then no more backspacing.
I'm getting the same error on Unity 5.2.3f1 ($$anonymous$$ac)
Answer by AndreasScholl · Dec 10, 2015 at 05:20 PM
Happened for me too.
I fixed the issue in our program by catching the exception and reducing the String-Length by 1 if it occurs.
try
{
newValue = GUI.TextArea(rect, stringToEdit, stringLength, style);
}
catch (System.Exception e)
{
if (e is System.ArgumentOutOfRangeException)
{
newValue = newValue.Substring(0, newValue.Length - 1);
}
}
Your answer
Follow this Question
Related Questions
Android Textfield locks out input until esc 2 Answers
Text.Field erratically updating 0 Answers
How to slow down GUI 2 Answers
TextField plus Return Key issue 2 Answers
Get key state while textfield has focus? 0 Answers