Search Unity

Unity UI How to pause OnCanvasHierarchyChanged?

Discussion in 'UGUI & TextMesh Pro' started by gsylvain, May 25, 2021.

  1. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    104
    Hi,

    our game contains a lot of complex UI prefabs. Some of them are proceduraly built at runtime.

    I was investigating why some of our views are taking a long time to appear. That view has 50+ small icons (image + TMPPro + layout) that are instantiated at runtime. I noticed that we get a lot of OnCanvasHierarchyChanged calls, more than expected. I feel like each time ONE element is added, the whole canvas is rebuilded. Is my assumption correct? If that's the case, is there a way to pause the UI "engine" while I am actively populating my UI? Something like:

    canvas.PauseHierarchyRebuild();
    ... create all dynamic ui ellements ...
    canvas.ResumeHierarchyRebuild();

    Thank you!
     
  2. JohnTomorrow

    JohnTomorrow

    Joined:
    Apr 19, 2013
    Posts:
    135
    Did you ever come up with a solution for this?