Search Unity

TextMesh Pro Feature Request: Callback to modify TMP mesh from another component.

Discussion in 'UGUI & TextMesh Pro' started by tessellation, Jun 2, 2020.

  1. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    The correct way to modify a TMP mesh (for example to do text animation, arcs, waves) is to do this during or right after TMP generates its base geometry. TMP might generate the geometry in UGUI Rebuild or in a PreRender type event.

    Currently we're modifying text vertices in LateUpdate when we detect that TMP properties have changed and we call ForceMeshUpdate(true) before UpdateVertexData. However, there are cases where this doesn't work, for example if our object gets enabled in LateUpdate by another object, then we're not able to modify the geometry until the next frame. This causes visual anomalies or we have to create hacks like detecting which phase Unity is currently updating objects in (i.e. LateUpdate) and then force the geometry to update in OnEnable.

    So in conclusion, please add a way to make geometry modifier plugins, for example a C# event or a way to register a plugin callback. This way TMP itself can drive mesh updating. Along with this, add a way to dirty the text (without modifying TMP properties) to force TMP to update when our geometry is animating. For example, if you have the text move along a curve or animate the phase shift of a wave. When our component detects that these properties have changed, it would dirty the TMP text.

    Thanks for consideration.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Adding a Callback to provide an opportunity for user code to modify the resulting geometry of the layout pass before TMP submits it to the mesh or canvas renderer does make sense to me. I will take a look at adding this.

    In terms of dirtying without changing a property, doesn't the ForceMeshUpdate() already provide this functionality?
     
  3. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    390
    Great, thank you.

    My understanding is that ForceMeshUpdate immediately updates the mesh, which is not what you'd want in this case. You want the mesh to update at the time it might normally update, for example if I were to change the font size or color of the text. Actually looking at the TMP source, it looks like havePropertiesChanged is public so we can just set that to TRUE.