TextMeshPro Input field keeps resetting text
I've got a UI like this that lets you choose how many of a unit to send. The up/down buttons should make the value go up/down, with a minimum of 1 and a max that depends on the situation. The double arrows should set it to min and max respectively.
Now, it doesn't matter what I do, whenever the textbox gets set by one of the arrows (or my keyboard for that matter), it resets to 1. I've tried stepping through the debug, and what I see is that on the 3rd line, text is = "5", but then txt.text still get's set to "1".
protected void SetText(string ctrlName, string text)
{
Transform txtTrans = m_trans.FindChildRecursive(ctrlName);
var txt = txtTrans.GetComponentInChildren<TextMeshProUGUI>();
txt.text = text;
}
If I drag the execution back to the 3rd line again, it'll be set properly to "5". It's very bizarre. Here's the settings for the TMP_Input field.
Answer by judahcline · Sep 10, 2020 at 12:57 PM
if it deletes code the second it appears then thats because you want the code that changes the text to be in a void update() {} command
Your answer
![](https://koobas.hobune.stream/wayback/20220613011550im_/https://answers.unity.com/themes/thub/images/avi.jpg)