- Home /
Issue with Text Mesh
Hello.
I've got a problem recently when override void OnPopluateMesh. Sometime it print this two errors: 1.Mesh.uv3 is out of bounds.The supplied array needs to be the same size as the Mesh.vertices array UnityEngine.Canvas:SendWillRenderCanvases()
2.Mesh.uv4 is out of bounds.The supplied array needs to be the same size as the Mesh.vertices array UnityEngine.Canvas:SendWillRenderCanvases()
This doesn't happen very often.
When this happens, the text mesh's uv becomes chaos. And this uv problem get right when ui rebuild(I am not sure, but the uv will get right when ui change something ).
I don't know how this problem arose.
Does anybody have any idea about this?
Thank you very much!
Version of Unity: 5.6.3f1 (64-bit)
Here is my code:
protected override void OnPopulateMesh(VertexHelper toFill)
{
if (null == font) return;
m_DisableFontTextureRebuiltCallback = true;
Vector2 extents = rectTransform.rect.size;
var settings = GetGenerationSettings(extents);
cachedTextGenerator.PopulateWithErrors(text, settings, gameObject);
IList<UIVertex> verts = cachedTextGenerator.verts;
float unitsPerPixel = 1 / pixelsPerUnit;
int charCount = (verts.Count - 4) / 4;
Vector2 roundingOffset = new Vector2(verts[0].position.x, verts[0].position.y) * unitsPerPixel;
roundingOffset = PixelAdjustPoint(roundingOffset) - roundingOffset;
Debug.Log("Populate111");
toFill.Clear();
UILineInfo[] uiLineInfos = cachedTextGenerator.GetLinesArray();
ClearLinksBoxs();
Debug.Log("Populate222");
InitUnderlineV4();
Debug.Log("Populate333");
UpdateEmojis(verts, charCount, uiLineInfos);
for (int i = 0; i < charCount; i++)
{
UIVertex[] charVerts = TextUtil.GetCharVs(verts, i, 4);
for (int j = 0; j < charVerts.Length; j++)
charVerts[j].position *= unitsPerPixel;
if (roundingOffset != Vector2.zero)
TextUtil.AddOffset(charVerts, new Vector3(roundingOffset.x, roundingOffset.y, 0));
ELink elink = GetELink(i);
if (null != elink)
{
if (null != elink.data.color)
TextUtil.SetColor(charVerts, elink.data.color);
if (elink.data.interactable)
elink.AddBox(charVerts[3].position, TextUtil.GetSize(charVerts));
}
if (IfshowEmojiSpr(i))
TextUtil.ClearUV(charVerts);
toFill.AddUIVertexQuad(charVerts);
}
Debug.Log("Populate444");
UIVertex[] linesVs = GetLinesVerts(verts, uiLineInfos);
int lineCount = linesVs.Length / 4;
Debug.Log("lineCount: " + lineCount);
for (int i = 0; i < lineCount; i++)
toFill.AddUIVertexQuad(TextUtil.GetCharVs(linesVs, i, 4));
Debug.Log("Populate555");
m_DisableFontTextureRebuiltCallback = false;
meshPoped = true;
Debug.Log("Populate666");
}
When this problem show up, it start with "Populate333"...
Answer by Nathan1258 · Apr 07, 2018 at 04:56 PM
Are you re-using meshes in your code, I had this problem and someone advised me to always create a new one?
Thank you for your reply! Your answer is very helpful to me. I will check that.
No problem, text back if it worked or you need more help
Your answer
Follow this Question
Related Questions
UI Text compression on android 1 Answer
Render Debug.Log as UI Text 2 Answers
What's your equivalent of old GUIStyle ? 0 Answers
Canvas is flipping, 2D game 0 Answers