Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Change TMP_Text.color After Calling BindToTMPChar* #191

Open
c3-hoge-fuga-piyo opened this issue Jan 5, 2025 · 0 comments
Open

Comments

@c3-hoge-fuga-piyo
Copy link
Contributor

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant