Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020.2 has been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

TextMesh Pro Long spikes from TextMeshProUGUI.Rebuild for no reason

Discussion in 'UGUI & TextMesh Pro' started by dadude123, Jul 21, 2018.

  1. dadude123


    Feb 26, 2014

    There's a container, a VerticalLayoutPanel, that has ~600 child lines.
    Each line has 2 sub objects that each have a TextMeshProUGUI component.

    The layout itself is very optimized, I'm disabling the vertical layout once I know it won't change anymore, and only enable it for one frame to do its thing when I know the children must have changed.
    The list entries themselves are not using any layout components, they're completely driven by anchors.

    Everytime my main-window moves, TMP rebuilds every textmesh object.
    Why can't that be cached or even completely avoided? It doesn't generate the mesh in worldspace, does it?

    Why is Rebuild() even called from the layout system when no local positions have changed.
    It's literally only the gameobject above the container (the window) that changes position.

    Any tips how I can avoid this?
  2. Stephan_B


    Unity Technologies

    Feb 26, 2017
    I believe the parent moving would trigger / lead to the UI / Canvas system thinking everything needs to be rebuilt. In this case, the TMP text component would get a call from the UI system to rebuild itself claiming the RectTransformDimensions have changed.

    This is frequent when using Stretch mode anchor positions.
  3. petergraham003


    May 5, 2018
    Each time I enable a UI screen in worldspace, CanvasUpdate.PreRender is getting called from which TextMeshProUGUI.Rebuild is getting called and causing a performance hit. I have tried solutions like removing StretchMode anchor positions, having nested canvas, correcting long point float values but nothing worked out. That performance hit cannot be ignored as it is causing a great jitter to user. Can anyone provide me a workaround or solution for this problem ?
  4. Rafael_CS


    Sep 16, 2013
    Canvas Layout works invalidating parent of type ILayoutGroup

    So... if you enable an IlayoutElement and the parent of ILayoutElement is a Layout Group, each IlayoutElement child of this group will be recalculate, regardless if only one child need this recalc (And if the parent of layout group is a layout group too, same thing happens to all children's.. until find a parent == null or a parent that is not a LayoutGroup)

    This approach of unity to recalculate layout prevent inconsistencies but generate HUGE overhead when activating and deativating objects.

    Only way to prevent this huge overhead is implementing your own layout group parent (and not inheriting from ILayoutGroup)

    I thing this is a huge mistake of unity layout rebuilder implementation.

    Another thing to prevent the huge lag spikes and random recalcs is to disable Pixel Perfect in root canvas. Pixel perfect call Transform Sync to every object of hierarchy on every layout recalc or transform move.

    Of course, text mesh pro could try implement a custom bool var to check if need recalculate layout when call CalculateLayoutHorizontal. This way will prevent huge overheads while activating and desativating objects
    Last edited: Feb 14, 2020