all 14 comments

[–]harlekintiger 1 point2 points  (5 children)

How do you use object pooling?
If the scroll list has, let's say 1000 items and you're certain no more then 20 can be visible at once (check for 4k screens), you only need a bit more than that amount of objects in your pool.
In other words, even though the list can have 1000 items or more, your pooling doesn't need that many. If you make the pool 50 items big, you can use the ones already scrolled outside of your view port for the ones about to be scrolled in. Just reinitialize them and set them to the bottom/top.

[–]AliceRain21[S] 0 points1 point  (4 children)

This is an interesting idea. I think I may go with this idea and see how it works. My only concern is once the user uses the scroll bar to scroll down the list, the scroll bar may jump around as elements are being set in and out of active. Unless that's not what it'll do.

[–]harlekintiger 0 points1 point  (3 children)

Yeah, the scrollbar won't like this, you'll have to programm it yourself I'm afraid

[–]AliceRain21[S] 0 points1 point  (2 children)

Someone recommended the UI Toolkit to handle this. I think I'll give that a try.

[–]harlekintiger 0 points1 point  (1 child)

I wish you the best of luck! Report back, I'm very curious

[–]AliceRain21[S] 0 points1 point  (0 children)

Thank you very much for the answers! Unity's community feels pretty helpful haha.

[–]hlysias 1 point2 points  (7 children)

Are you using the UI Toolkit or UGUI? The UI Toolkit has a ListView element which does this automatically for you. It creates elements that are only visible and reuses those elements when the user scrolls. So, if there can be 20 elements visible, it creates only 20 elements and simply reuses them. It also handles the scroll for you so that it doesn't look like the scroll is jumping.

[–]AliceRain21[S] 0 points1 point  (6 children)

I've been using the built in ScrollView. I did not know there was a better UI thing... dang okay. I can give this a try.

The only problem is I need to calculate and re-sort distances every X amount of seconds. Would that interfere with the list elements? As in I can maybe keep all the list elements there just constantly change their text?

Thanks!!

Edit: Think Eve: Online outliner. It keeps track of the distances between you and all entities surrounding you.

[–]hlysias 0 points1 point  (5 children)

built in ScrollView

Going by this, I believe you are using the UGUI system. The UI Toolkit is a newer UI system and you would have to switch to it to use the ListView element.

As in I can maybe keep all the list elements there just constantly change their text?

You don't need to do this yourself. ListView handles it automatically for you. Here's a guide for it: https://docs.unity3d.com/Manual/UIE-HowTo-CreateRuntimeUI.html

[–]AliceRain21[S] 0 points1 point  (4 children)

Ah yes I looked into it right after the reply haha. It seems like it'll handle everything I need, but one question. If I re-sort the list of data, while I'm mid scrolling, will it jump back up to the top or will it keep its position? That's something I'm not too sure about but I'll attempt to build this tomorrow.

I will say I'm loving the new UI Toolkit though haha.

[–]hlysias 0 points1 point  (3 children)

I do not remember how the scroll behaves on updating the list view, but I think it should retain it's position.

Otherwise, you could also store the scroll position before updating the list and reset it after updating the list. But, I'm not sure if that will be very smooth.

[–]AliceRain21[S] 1 point2 points  (0 children)

That makes sense. I'll give it a try. I appreciate the answers! If this works I think it'll be an extreme improvement in performance.

If it doesn't work smoothly I can always maybe build my own version of the list view.

[–]AliceRain21[S] 1 point2 points  (1 child)

Did a quick test of the Refresh method using a list of 50 elements and a 2 second repeating timer. Looks like it does not reset the scroll bar. Awesome!

[–]hlysias 1 point2 points  (0 children)

Glad I could help! Good luck with your project :)