- Home /
TMP_Input Field Destroys text
Hello, I am trying to set the text of a TMP_InputField
using the below:
caption.GetComponent<TMP_InputField>().interactable = true;
caption.GetComponent<TMP_InputField>().text = "Hello, world";
If I print out my text immediately afterwards using caption.GetComponent<TMP_InputField>().text
, I get the correct result. However, in the Game view, the text is cut off and displays "Hell". Whatever I try, only 4 characters are displayed. How should I debug this?
Answer by Captain_Pineapple · May 10 at 01:41 PM
my guess would be that this is an issue of your UI Layout or the text component settings. There is a "horizontal Truncate" option that you could try to remove. Aso try to raise the width of your text element.
The width is quite large, so I don't think it's that. I can manually put in lots of text when running the app. The problem is setting the text manually cuts it off for some reason.
Answer by unity_QiUlE25oqh9S_w · May 10 at 06:26 PM
For those who are coming across the same problem, I still have not found why this happens, but my solution was to create an enumerator where I set the text in the next frame instead of the same frame as below:
IEnumerator CreatePostHelper(...) {
// Instantiate caption GameObject
GameObject postPanel = GameObject.Instantiate(PostPanelPrefab, PostPanelContent);
...
yield return new WaitForEndOfFrame();
caption.GetComponent<TMP_InputField>().text = postData.caption;
yield return null;
}
Your answer
Follow this Question
Related Questions
how to stop input field from restarting the string value? 0 Answers
Check if input field is something based on if a text is something 1 Answer
Clear fields after submit 3 Answers
How to convert text field to input field and back again? 0 Answers
I have a C# script with InputField and I want to get text from this input field to another script 0 Answers