and later in my start, I call the following function.
private void init_UI_fps()
{
UI_fps.GetComponent<Text>().text = "FPS Text INIT";
}
I mean yeah, sure. I know I need to set the rect transform limits and what not to fit the screen, but I can’t get anything to show up at all. what gives? Am I missing some essential command?
Well the standard way is not to create your UI component at runtime. Yes, it’s possible, if you really know what you’re doing, but you don’t yet, so stick to the standard way.
The standard way is to create and configure your UI (which needs to be inside a Canvas — probably the key bit you’re missing) in the editor. Then your code just gets a reference to that already-created Text, and sets the text property at runtime.
If you don’t know how many texts you’re going to need, you can use Instantiate to clone them (or instantiate a prefab) at runtime. And then you’ll either need to use something like a VerticalLayoutGroup to arrange them, or you’ll have to come to grips with RectTransform to learn how to position them dynamically from code.
Finally, I recommend you don’t use Text any more. Add the TextMeshPro package to your project, and use a TextMeshProUGUI everywhere you would have used Text prior to 2017 or whatever. TextMeshPro is better than the built-in Text in every way.
Just be aware that if you care about learning the latest to the exclusion of learning the old that UnityEngine.UI is itself to be replaced by UnityEngine.UIElements.
and it kind of works? But I think there’s something wrong with some of the settings because like I said - the text is super blurry and not at all sharp like I imagine it should be.
To clarify - the thing I need to fix is somewhere in the canvas render mode. But I haven’t figured out what to fix yet or how.
Have you played with the UI elements manually in edit mode first? It’s much easier to see how they work and mess with settings to find out what looks best.
In general, you’ll want to ensure your Canvas’s Canvas Scaler component is set to “Scale With Screen Size” and pick a Match property that works best for you (I prefer 1: fully set to Height) and increase your Reference Resolution to something practical like 1920x1080.
If you need text items to be rendered to a small part of the screen, you can try increasing the item’s font size and scaling it down. This feels super hacky to me, but it often gets you a clearer result. I think this is mostly applicable to world space canvases, though.