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?
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.
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;
}