Hi, might be a stupid question, but I haven’t been able to figure out how to change the text for the TextMeshPro Text in my UI via script. I tried:
TextMeshPro mText = gameObject.GetComponent();
mText.text = “test”;
gets me the error: Object Reference not set to an instance of an object.
Same with mText.SetText(“test”) and
TextMesh mText = GameObject.GetComponent();
mText.text = “agdsf”;
just says, there’s no TextMesh attached to the GameObject.
Script attached to the GameObject and using TMpro. It works if i create it as a 3d object, but not as part of the UI. Not quite sure what I’m missing, looked over the script tutorial for the plugin and there it’s just written as stated above. Thanks!
So… how do actually edit the text of a textmeshpro control?
Here’s my issue.
I have a canvas/screen where I edit the data of a member of a list, when I load the screen I fill up the fields with existing data, using a method from my UIManager:
public void SetUIData(ActionCardItem actionData)
{
ActionWhatField.text = actionData.What;
ActionWhoField.text = actionData.Who;
ActionWhenField.text = actionData.When;
ActionRewardField.text = actionData.Reward;
}
Action***Field are of the type TextMeshProUGUI.
The first time it works but when I add a new item in my list and load that one, I get the data from the previous one.
Is there some special treatement when you try to put an empty screen in the text field of a texxtmeshpro?
To get the component type for something like this, just look at the text label of the component to the left of (Script) and remove the spaces. “Text Mesh Pro UGUI (Script)” as the label of the component reveals that it is a TextMeshProUGUI type. For components that aren’t labeled as (Script), just remove the spaces – “Rect Transform” component is a RectTransform type. For your own scripts – just make sure you use Pascal case (ex. “PascalCase”) for their class names in C#.
There are two TextMesh Pro components… the normal component is of type and works with the MeshRenderer and a replacement for the old TextMesh. Then the UGUI component is of type and works with the CanvasRenderer.
using UnityEngine;
using TMPro;
public class NumberWizard : MonoBehaviour
{
[SerializeField] TextMeshProUGUI m_Object;
void Start()
{
m_Object..text = "Enter Your Text Here";
}
}
Now from Unity you have to bind your TextMeshPro object with m_Object.
I Know I am Too Late For Your Answer But At The First, You Need Add-On The Top (Using TMPro)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class unknown: MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}