Search Unity

TextMesh Pro Batching Problem

Discussion in 'UGUI & TextMesh Pro' started by _watcher_, Dec 14, 2020.

  1. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    261
    I'm trying to make batching (dymanic/static/any) work with TMPro in URP/HDRP/Builtin-renderer/any - no success. If you know this to be not working currently, or know a solution - please let me know either way, so that i can move on.

    I've made bare bone URP project (also tested built-in non-SRP renderer), placed 3D TMPro Text into scene. Added some text. Static batching doesn't seem to work at all. Dynamic batching seems to have upper limit on number of vertices (with which a mesh can be dynamically batched) in Unity. If i use around less than 30 letters (per textfield) in the text fields in the following example, it will batch dynamically. If i use more, it wont batch and each additional (duplicated) textfield incurs +1 draw call. I've duplicated the example textfield 39 times (thus there are 40 textfields in the scene, which results in 41 draw calls.

    https://ibb.co/GssPYxw

    Setup i use:
    Unity 2020.1.17f1
    Text Mesh Pro 3.0.3
    no lights (TF no shadows/probes/reflections/GI; URP Asset lights/shadows disabled)
    each TextField has Static/Static Batching flag ticked
    URP Asset SRP Batcher enabled
    URP Dynamic Batching enabled
    tested in/on: Editor/Android device

    EDIT1: Tested TMProUI -- canvas. Batches correctly. Weird! Still does not solve my problem.

    EDIT2: I was able to further optimize the number of draw calls, by manually calling
    Code (CSharp):
    1. StaticBatchingUtility.Combine(batchableRoot);
    with a delay (frame 2).

    It seems that the TMPro instances are not in their final state on frame 1 (perhaps its still parsing the text tags or ... idk [TODO: check if the fields send some callbacks when done parsing/etc]), so the static batching doesn't seem to work on the fields. When i manually call StaticBatchingUtility on a root into which all the fields are placed, that cuts the number of DrawCalls to a half. Still thinking.. if i could group the fields by weights i could separately batch groups of the same weights to further reduce this [TODO]). Something tells me TMPro is actually doing this automatically if all goes well, but i might have messed up something so it doesn't (unsure).

    Also im thinking other optimizations, but it all involves asynchronously calling StaticBatchingUtility to batch the fields, so that's the bottom line - i assume that the TMPro instances are not synchronously done with their work on frame1 and thus don't automatically statically batch. This would make sense, for example when doing localization .. how does the field know when to batch (when are we done setting the loc text?). 'Advanced' section in the docs would be awesome for understanding under-the-hood things such as these, for those of us who don't want to dig into the asset's code ;).
     
    Last edited: Dec 15, 2020
    cxode and vitaliano_fanatee like this.
  2. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    1.5 years later, did you learn any more about batching TMP objects? I'm currently trying to figure out how to reduce the draw calls caused by them.
     
  3. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    261
    I was going to reply "Since i switched to Phaser3, i do not have this problem", but decided against it.. oh darn it did i just speak my thoughts out loud! Well, be as it may, i'd really like to help you with that, but i really don't remember what further optimizations i came up with 1.5yrs ago, if any. I suggest you ask on TMPro forums or post on Unity Answers (or both). Oh smash it, i just realized we are in the TMPro forums, welp good luck and keep your head up (or down, i heard Prayer works in cases of problems impossible to solve by corporal means).
     
    cxode likes this.