redbluegames / unity-text-typer

Text typing effect for Unity uGUI Text components
MIT License
307 stars 28 forks source link

Sprites reappear if followed by text with an Animation #38

Closed edwardrowe closed 4 years ago

edwardrowe commented 4 years ago

Repro: The following is observable in master right now by running the test scene and skipping + advancing.

  1. Print text to a TMProUGui component that includes sprites. Ex: "This is a sprite !"
  2. Change the text to something else.
  3. Call UpdateGeometry on each MeshInfo. Ex:
        var textInfo = this.TextComponent.textInfo;
        for (int i = 0; i < textInfo.meshInfo.Length; i++)
        {
            textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
            this.TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
        }

The issue is sort of with TMPro. As an optimization they leave the SubMesh objects around that are used to render the sprites. They use the same SubMesh objects for fallback fonts. Then, in TextAnimation, calling TextComponent.UpdateGeometry(this.textInfo.meshInfo[i].mesh, i); causes the garbage sprite mesh info to be resupplied to the SubMesh.

We should be able to use TextInfo.ClearMeshInfo() before every print to fix.