How to add text to a 2D gameobject, non-UI related?

An embarrassingly simple question, given the scope of what I want to do, but how do I quite simply have a gameobject have text on it, that’s not related to the UI at all?

I want to create a number of “placeholder” objects to serve as prototypes whilst I develop a 2D game before later onboarding an artist to replace them with proper sprites. So in essence, I want a “square” which contains its own text but behaves as a simple object, not part of the UI.

All the research I can find talks about associating text with UI, whereas I just want a simple gameobject with text on it.

I create a gameobject via Right Click → 2D Object → Sprites → Square. Now how do I add text to it?

I can’t seem to use a text mesh since this conflicts with the square mesh renderer (I do want a square, not just text by itself, so I can easily resize the shape of the object and make its outline apparent as a square).

I tried using TextMeshPro → Text. I can create text which appears exactly how I want it within the Scene view:
7398737--903935--upload_2021-8-8_20-1-38.png

But the game view? It disappears:
7398737--903938--upload_2021-8-8_20-1-51.png

How do I accomplish this embarrassingly simple task? Thanks.

Check the sorting order of the text. Two options would be:

  1. Move the text on the Z axis (typically negative value towards the camera)
  2. Add a sorting group to either object Unity - Manual: Sorting Groups

Hi thanks for the reply. Yes I sorted it now by adding a 3D text object. 3D → Text Mesh Pro. Then putting the Z position as -1.

A slight effect: When moving, the text will move slightly. This isn’t a big deal but a bit curious why this is so. And also why the text appears under 3D instead of 2D for a 2D game.

Text Mesh Pro will render text on a mesh outside of the UI component. It’s a flat plane essentially so it’s about as 2D as it gets in a 3D engine. SpriteRenderers end up on a mesh in some form too!

For the moving text - is your camera set to orthographic? Is textmeshpro set to autosize or anything? using PixelPerfectCamera?