Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by goldenfoxx · Jul 24, 2014 at 09:22 PM · texttextmesh

Using TextGenerator

There is little to no information about the TextGenerator, I am trying to use it to allow me to create 3d text and word wrap to set a bounds, however it apparently generates Vertices but what am I supposed to do with them.

Again I have found no information on this, and am wondering what the heck this is good for ?

TextGenerator Unity Reference

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AnonHandler12 · Mar 14, 2015 at 05:17 PM 0
Share

Did you ever find an answer to your question? I'm also generating Vertices but nothing more and I really don't know what I'm supposed to do.

EDIT: the solution is "simply" that you need to assign to the CanvasRenderer the material needed by your font. It'd be nice if the example in the documentation could show this.

$$anonymous$$g. canvasRenderer.Set$$anonymous$$aterial(font.material, null);

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by MrFloat · Sep 04, 2016 at 12:36 PM

For those who are still searching how to use the TextGenerator class:

I personally had some problems setting up the TextGenerationSettings. When you create your own TextGenerationSettings, it has no sensible default values
(probably something to do with it being a struct, but on the same note, not sure why it was decided to make this fairly large container into a struct even though you can end up passing it to the TextGenerator a lot of times, forcing a copy of all the values inside).
Bellow is just an example of the settings I ended up using in my tests but some important ones to not miss are lineSpacing and scaleFactor as the default 0 values can mess up the vertex positioning a lot.

 var m_TextSettings = new TextGenerationSettings();
 
 m_TextSettings.textAnchor = TextAnchor.MiddleCenter;
 m_TextSettings.color = Color.red;
 m_TextSettings.generationExtents = new Vector2(100, 100);
 m_TextSettings.pivot = new Vector2(0.5f, 0.5f); ;
 m_TextSettings.richText = true;
 m_TextSettings.font = m_Font;
 m_TextSettings.fontSize = 14;
 m_TextSettings.fontStyle = FontStyle.Normal;
 m_TextSettings.verticalOverflow = VerticalWrapMode.Overflow;
 m_TextSettings.horizontalOverflow = HorizontalWrapMode.Wrap;
 m_TextSettings.lineSpacing = 1;
 m_TextSettings.generateOutOfBounds = true;
 m_TextSettings.resizeTextForBestFit = false;
 m_TextSettings.scaleFactor = 1f;

As mentioned in one of the comments, if you are using a CanvasRenderer, you need to set material and mesh:

 m_CanvasRenderer.SetMaterial(m_Font.material, null);
 m_CanvasRenderer.SetMesh(m_Mesh);

If you are using a MeshRenderer, you probably want a MeshFilter component as well and assign a new mesh to it:

 GetComponent<MeshFilter>().mesh = m_Mesh;
 m_MeshRenderer.sharedMaterial = m_Font.material;

To generate a mesh from TextGenerator, I made this extension method:

 public static class TextExtensions
     {
         static public void GetMesh(this TextGenerator i_Generator, Mesh o_Mesh)
         {
             if (o_Mesh == null)
                 return;
 
             int vertSize = i_Generator.vertexCount;
             Vector3[] tempVerts = new Vector3[vertSize];
             Color32[] tempColours = new Color32[vertSize];
             Vector2[] tempUvs = new Vector2[vertSize];
             IList<UIVertex> generatorVerts = i_Generator.verts;
             for (int i = 0; i < vertSize; ++i)
             {
                 tempVerts[i] = generatorVerts[i].position;
                 tempColours[i] = generatorVerts[i].color;
                 tempUvs[i] = generatorVerts[i].uv0;
             }
             o_Mesh.vertices = tempVerts;
             o_Mesh.colors32 = tempColours;
             o_Mesh.uv = tempUvs;
 
             int characterCount = vertSize / 4;
             int[] tempIndices = new int[characterCount * 6];
             for(int i = 0; i < characterCount; ++i)
             {
                 int vertIndexStart = i * 4;
                 int trianglesIndexStart = i * 6;
                 tempIndices[trianglesIndexStart++] = vertIndexStart;
                 tempIndices[trianglesIndexStart++] = vertIndexStart + 1;
                 tempIndices[trianglesIndexStart++] = vertIndexStart + 2;
                 tempIndices[trianglesIndexStart++] = vertIndexStart;
                 tempIndices[trianglesIndexStart++] = vertIndexStart + 2;
                 tempIndices[trianglesIndexStart] = vertIndexStart + 3;
             }
             o_Mesh.triangles = tempIndices;
             //TODO: setBounds manually
             o_Mesh.RecalculateBounds();
         }
     }

Hope this helps some people;

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gsmetzer · Jan 19, 2017 at 11:26 PM 0
Share

Has anyone been able to use this on a $$anonymous$$eshRenderer? I can't seem to convert IList to an array.

avatar image MrFloat gsmetzer · Jan 19, 2017 at 11:34 PM 0
Share

What does your code look like? The Get$$anonymous$$esh() function should populate a mesh for you if you're using that code.

avatar image gsmetzer · Jan 19, 2017 at 11:59 PM 0
Share

I'm a bit of a noob to this, I think the issue is getting the IList UIVertex generatorVerts = i_Generator.verts; data in order to calculate vertex positions for the mesh. I'm just not sure UIVertex is compatible with $$anonymous$$eshRenderer. Thanks for your help on this so far.

avatar image MrFloat gsmetzer · Jan 20, 2017 at 12:15 AM 0
Share

Well you are correct at assu$$anonymous$$g that UIVertex data is not compatible with $$anonymous$$eshRenderer. That data structure is a more efficient/propper way of storing per vertex data but most things like $$anonymous$$eshRenderer uses the old OpenGL format of seperate array lists of data and that's why Get$$anonymous$$esh() function goes through UIVertex and seperates it out into seperate vertex, color and uv lists. The UIVertex data that you get back from the generator is also already optimised for text purposes and defines every character with 1 quad (4 points) rather than the generic format of 2 triangles (6 points). So the wierd looking for loop that goes through every character creates a list of indices that maps 4 actual points in the vertex data list to 6 entries.

avatar image MrFloat gsmetzer · Jan 20, 2017 at 12:23 AM 0
Share

Not sure what problems you're running into but if it's not rendering propperly for you try having a breakpoint and checking the UIVertex list that the generator gives you. I mentioned making sure to set "lineSpacing" and "scaleFactor" values on my post because leaving them at 0 will give you very odd values from the generator but I might have missed some other important properties that need to be set. Just wondering if the data your working with from the generator is actually correct.

avatar image gsmetzer MrFloat · Jan 20, 2017 at 01:00 AM 0
Share

Got it working! Thanks for your info and help with the code. UpVoted.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Adjusting the transform width to match wrapped text (TextMeshPro) 0 Answers

UnityEngine.Input.GetMouseButton(1)) issue 1 Answer

Cannot get 3D Text/Text Mesh to wrap or a attached collider used as a button to scale based on word count. 2 Answers

Change Textmesh.text from script 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges