About 'Using Text Mesh For Labels'!

In this video (objectives)…

  1. How to use Text Mesh in Unity
  2. Text Mesh vs UI Text
  3. Using the [SelectionBase] attribute
  4. Using 'GetComponentInChildren()'

After watching (learning outcomes)…

Use Text Mesh to label objects in the world for debug.

(Unique Video Reference: 5_RR_CU2)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

You can use void Awake() instead of void Start() to find a TextMesh component in the editor mode when an object is “starting up”, so there’s no need to get the TextMesh on every Update() call.

Thanks for this, however I’m not sure the text will update to the new coordinates as we move the blocks in this case?

Sorry, I meant to just grab the TextMesh component into an instance variable in Awake() (kind of like you were meaning to do with Start() in the video), and update it in Update(). I was trying to get that done before watching the full video myself and ran into the same problem, until some example somewhere pointed towards using Awake() for editor mode scripts.

1 Like

It was nice to learn about the 2 new annotations [SelectionBase] and [ExecuteInEditMode]. Did not know this sort of stuff was possible till now. I feel like this course is teaching concepts properly. Well done.

1 Like

I enjoyed the course, though I wasn’t sure why you opted to use GetComponentInChildren instead of just serializing a field for the TextMesh and then dropping it into the inspector and saving the prefab. I did this, then added

textMesh.text = snapPos.x / gridSize + "," + snapPos.z / gridSize;

to the update function. Everything works and updates as it’s supposed to without having to trigger anything for the changes. Of course I only knew how to do this because of your tutorials @ben :slight_smile:

I assume maybe using code to locate the TextMesh is just to remove the possibility of a game designer from coming along and messing things up. I’d appreciate your thoughts on this.

That’s fine Ash, there’s always many ways to do things.

I did it this way because it’s busy-work for the designer, that is they have no choice so why give them the false option?

That makes sense. The more I think about it, your way is clean and comes with fewer mistakes.

@ben

I want ask something because im confused about the Way you scale the Font.

In the instruction u Scale down the transform of the GameObject.
would it not be better to change this with Character Size?

if you make 100 Font Size (and propally you scale it down on every axis to 0.3)
you also can make the Font Size to 100 and then Change the Charater Size to 0.03 this will end up in the Same result without touching the GameObject transform.

Edit: The reason why character size is 0.03 instead of 0.3 is because our main object got a scale of 10 maybe 9 so the font need to be 100 time smaller to be the same like 0.3 (just as information why its 0.03)

Or did this solution would have a side Effect?

1 Like

So i had one small problem with the [SelectionBase] and not sure what I did wrong. But it doesn’t work and actually now whenever I click anywhere in the editor it selects another cube and seems to jump to different cubes on each click in no random order, and it is not selecting the cube object in most cases.

However i downloaded Ben’s code from github and that works was expected. But i cannot find what I did wrong. It was pretty straight forward to implement. Anyone else have the problem? I am running 2017.3, unless it is a bug in that version

Privacy & Terms