- Home /
InputField add text 'StackOverflowException' error
Hello,
I am currently working on the in-game console and I keep getting one error. What I do is when I type something in the input field I check if the input field text contains space char and if so I want to change the text color by adding color tag, but everytime I try to add color tag I get this error:
Error:
StackOverflowException
TMPro.TMP_InputField.set_text (System.String value)
I am most likely missing something obvious as always.. Can someone explain to me why is this happening?
Thank you!
Script:
public void OnValueChange (string _text)
{
if (_text.Length > 0)
{
char[] chars = _text.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] == ' ')
{
if (startCommand) return;
_inputField.text += "<color=#F3B028>"; //The error points to this line
_inputField.selectionAnchorPosition = _inputField.text.Length;
startCommand = true;
return;
}
}
startCommand = false;
}
}
Answer by Rukas90 · May 05, 2018 at 10:17 PM
Nevermind, just found the issue.. So the problem was I call this function on 'OnValueChanged' on input field, so everytime I added text I called this function again and again in this endless loop.. The solution was simple just set 'startCommand' before adding the text.
Your answer
![](https://koobas.hobune.stream/wayback/20220612162104im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
IME(Input Method Editor) Chinese Pin yin 0 Answers
Assertion Failed? 0 Answers
What is wrong with these two lines of scripting? 1 Answer
Display strings from a list in a text box 1 Answer
Unity 2017.1 Mac builds not opening 0 Answers