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

Question How many is too many?

Discussion in 'Scripting' started by Leuki, Oct 11, 2022.

  1. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    So I'm pulling json data from firebase and then pushing this data to prefabs, like user messages and then these are then set active in the scroll view. I'd like to use object pooling but with how unitys scroll rect doesn't react well in my experience, I was wondering how many UI prefabs could I instantiate instead without it being a processing issue... I don't expect there to be more than 100-500 objects being pulled at a time.
     
    Last edited: Oct 12, 2022
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    double or triple the amount you can fit on the screen, and that's a rough ballpark of how many objects you want to have active in the scene. certainly not in the hundreds.
     
    Bunny83 likes this.
  3. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
     
  4. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    Pooling*. Grammar police need not reply...
     
  5. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    As it is now with my current pool, it has 100 message objects active at once. That doesn't seem to be an issue. I haven't tried to instantiate 100 message prefabs yet but I'd assume it'd work. But if it were to be 500 message prefabs, then maybe it would start to lag
     
  6. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,525
    And you have low end testing devices? You know, the only way to know what is too much is to test it on the actual hardware it's supposed to run. If you have only high end testing devices your results may be skewed heavily.
     
    Leuki likes this.
  7. CodeKiwi

    CodeKiwi

    Joined:
    Oct 27, 2016
    Posts:
    119
    I’ve found loading too many UI elements can make it lag a bit on loading as you mentioned. In our case we had over a hundred achievements and it created a noticeable delay on some mobile devices.

    Options:
    • Paging
    • Don’t create all records at once e.g. maybe instantiate one per update call. Unfortunately this doesn’t look good as you can see the list expanding.
    • I found the layout elements can be a bit slow and normally manually place the items instead.
    • Having another canvas for the elements can also help.
    • If each record is the same height then I’d recommend recycling the elements like the UIToolkit ListView. So if you have 1000 records but can only see 10 at once then just create 10 and update the position and rebind the data while scrolling.
     
    Last edited: Oct 12, 2022
    NicBischoff, Leuki and Bunny83 like this.