Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Optimizing Large Quantity of UI GameObjects.

Discussion in 'UGUI & TextMesh Pro' started by jussch, Apr 11, 2022.

  1. jussch

    jussch

    Joined:
    Jan 2, 2018
    Posts:
    7
    Hey there!

    I'm building an incremental game in Unity where almost every thing in the game is in the UI. This means I have several lists of many many GameObjects, (hundreds of upgrades) spread across multiple tabs, and this seems to slow down the game a lot.

    I am caught between two solutions:
    1) Enable/Disable GameObjects when a tab is not in use. This puts my FPS to about 200, so pretty fast, but it chugs a bit more when swapping between views. A noticeable lag-spike occurs. Triggering a bunch of OnEnable/OnDisable on UI objects being the likely culprit.
    Because of the above problem, I've searched for optimization techniques, and found the below solution.
    2) Enable/Disable Canvas behaviors. Instead of the disabling the entire object, just disable the parent canvas and using some custom render groups to minimize my script `Update` calls. This speeds up switching between Tabs quite a bit, however the FPS now floats at around 100, so half the speed.

    My question is this: is it possible to get the best of both solutions? AKA, telling unity to ignore a large chunk of the GameObject hierarchy without a lag spike when you enable and disable them?

    Thanks!
     
  2. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    Use CanvasGroup component with alpha 1 or 0 to turn things off.
     
  3. jussch

    jussch

    Joined:
    Jan 2, 2018
    Posts:
    7
    That is essentially what I'm doing. Its just the vast number of objects still weigh down the game when they are enabled but not visible.