Search Unity

How should I manage this list of items?

Discussion in 'Scripting' started by UniversalGesture, Oct 19, 2019.

  1. UniversalGesture

    UniversalGesture

    Joined:
    May 29, 2017
    Posts:
    125
    I want to make an app were the user can scroll through many items (vertically).
    My question is how should I manage these items in the list.
    Do I just keep adding instances to my list or do I need to delete existing ones that are not in view?

    Thanks in advance
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    The simpler way to do it is just to create all your items in a scrollable container and allow the user to scroll through them. There's nothing inherently wrong with this.

    However, if your list is significantly longer than what fits on screen at one time, you may be able to get better performance by loading only a few at a time and getting rid of ones that are far out-of-view. Or even better, use object pooling to "re-use" the out-of-view objects by turning them into the newly-in-view objects.

    These sorts of tricks become more important if you want to implement certain features like "infinite scrolling", or if you are loading/fetching your data from a slow source (e.g. downloading it from online) in batches.

    If you're not sure if you need to do anything tricky, I suggest you try the simple option first and see if you run into problems.
     
    UniversalGesture likes this.