LitMotion
LitMotion copied to clipboard
Unable to Change TMP_Text.color After Calling BindToTMPChar*
https://github.com/AnnulusGames/LitMotion/blob/f7df4966aa30482fb739148aba2bc7bc672dfaf6/src/LitMotion/Assets/LitMotion/Runtime/Extensions/TextMeshPro/TextMeshProMotionAnimator.cs#L284-L290
I suspect that the state is not being reflected on the Canvas because TMP_Text.UpdateVertexData
has not been called after modifying the vertex data of each mesh.
After testing with the following simple implementation, it was confirmed that the presence or absence of UpdateVertexData affects the behavior.
var textInfo = text.textInfo;
for (int i = 0; i < textInfo.characterCount; i++)
{
var charInfo = textInfo.characterInfo[i];
if (!charInfo.isVisible) continue;
var materialIndex = charInfo.materialReferenceIndex;
var vertexIndex = charInfo.vertexIndex;
var colors = textInfo.meshInfo[materialIndex].colors32;
var charColor = Color.red;
for (int n = 0; n < 4; n++)
{
colors[vertexIndex + n] = charColor;
}
}
for (int i = 0; i < textInfo.materialCount; i++)
{
if (textInfo.meshInfo[i].mesh == null) continue;
textInfo.meshInfo[i].mesh.colors32 = textInfo.meshInfo[i].colors32;
textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
text.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
}
text.UpdateVertexData(); // If this line is missing, it will be fixed to red regardless of the content of text.color.