Search Unity

Question Batch TextMeshPro - Text Components, how?

Discussion in 'UGUI & TextMesh Pro' started by d3eds, Jul 17, 2022.

  1. d3eds

    d3eds

    Joined:
    Jul 17, 2022
    Posts:
    53
    Note, these are the TextMeshPro - Text components, which don't have a Canvas, only Rect Transform.

    Of the kind highlighted here:

    TMP_type.jpg

    Have made the TextMeshPro objects Static, and they are all exactly the same objects (prefabs) instantiated into positions from which they never move, never scale, never rotate.

    Yet am unable to make them batch.

    Is there a way to do this?

    2019.LTS TextMesh Pro 2.1.6 (Verified Version for this LTS)
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you please confirm the following?

    - You want to use the normal <TextMeshPro> components which use the MeshRenderer as opposed to the <TextMeshProUGUI> component which works with the Canvas Renderer. Correct?

    How much text do each of these text object contain? This is related to batching limitations for the MeshRenderer where there is a limit on the number of vertex attributes.

    Are each of these text components using the same material?

    When you instantiate these text components, are you manually assigning a font asset or material preset to them?

    P.S. I would suggest taking a look at example "Benchmark (Floating Text)" which spawns 250 text objects which should all be batching. These scene and related scripts could be useful in helping you figure out why you are not getting batching.
     
  3. d3eds

    d3eds

    Joined:
    Jul 17, 2022
    Posts:
    53
    Thanks for your prompt response!

    Can confirm, yes, as you say. That: TextMeshPro Components with the Mesh Renderer.

    Not the UGUI version.

    Each "unit" of this object with this component has a single character. Almost exactly like your sample.

    Your sample spawns 250 static objects, and 250 that move up and count up. None of them batch, so there's 504 (from memory) batches. Ground image etc taking it over the 500 objects.

    Each text component is using the exact same material. I'm not manually assigning a font asset or material preset, because that's already been done in the prefab. So merely instantiate a prefab - each exactly the same.

    I'm testing with between 128 and 192 text objects, so should be well below the vertex count limitation for batching.

    In the same project, I'm able to batch sprites, particles and other geometry absolutely reliably.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Here is a screenshot of the Stats window when I try the same example scene using Unity 2020.3.36f1 with version 3.2.0-pre.3 of the TMP package. The results should be the same with Unity 2019.4 using your version of TMP or version 2.2.0-preview.3.

    upload_2022-7-19_23-16-16.png

    As you can see they are batching. Now we just need to figure out what is causing those objects not to batch in your case.

    In your Project Settings - Player Settings - Other Settings, do you have Dynamic Batching Enabled?

    I presume you are using the normal render pipeline and not URP or HDRP. Correct?
     
    kumawatb003 likes this.
  5. d3eds

    d3eds

    Joined:
    Jul 17, 2022
    Posts:
    53
    Yes, Builtin Renderer is being used. Dynamic batching is OFF, as I'm trying to achieve static batching, not dynamic batching.

    The purpose of all this is to be able to animate the Materials uniquely, via Animation Legacy components, which automatically Material Property Block their changes.

    This approach seems to work for all other types of Unity objects and material/shaders, just not for TMP.

    Is there something I need to change about the TMP shaders so they will become static batching capable?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The old TextMesh doesn't static batch either.

    Reading the documentation on Static Batching, it seems the issue is related to both the TMP component and the old TextMesh having a Tangent vertex attribute + UV2 in the case of TMP.
     
  7. d3eds

    d3eds

    Joined:
    Jul 17, 2022
    Posts:
    53
    Any way to use Dynamic Batching in such a way that Animation (Legacy) or MaterialPropertyBlock settings done manually don't break the batching?

    As it is now, the moment something is changed, the Dynamic Batching breaks for each object that's modified, and when that's all of them, it's a molasses.