Search Unity

Where to put UIs if temporarily don not need to display it?

Discussion in 'Immediate Mode GUI (IMGUI)' started by 769270865, Sep 24, 2017.

  1. 769270865

    769270865

    Joined:
    Feb 10, 2016
    Posts:
    23
    Is it a good idea to set UI elements as prefab and load in through resource when needed? Or it would be a good idea just to put UIs Outside of the view?
    Which one will take less resource?
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    You mean Instantiating that prefab every time you need it and destroying it if you don't need it anymore? That sounds like a really bad idea, it will result in creating a lot of garbage.
    It is however a good idea to use prefabs to initially instantiate your ui. For example if you have a long list of items, it is really good to create those items via a prefab and then populate them with the data you want and then enable the objects. This results in shorter loading times compared to serialized data from a unity scene.

    But back to your question. There are two quite good ways to do it:
    - Disable the canvas your not needed ui is in (You can also have nested canvases, which you also should have)
    - Just disable the game objects you're not needing. This won't create any garbage and makes sure those elements won't be included in any redraw calculations when they are disabled.
     
    769270865 likes this.