qiankanglai / LoopScrollRect

These scripts will make your UGUI ScrollRect reusing cells, to improve performance, loading time and draw calls.
http://qiankanglai.me/2015/08/15/LoopScrollRect/
MIT License
2.29k stars 476 forks source link

[Help] An error occurs when more objects are created than the number of objects what I can see. #153

Closed hyunwoo9120 closed 1 year ago

hyunwoo9120 commented 1 year ago

The scroll doesn't work properly and the next object doesn't appear. (I can see only two objects on the screen, but four objects are created, and when I scroll, all objects in the content are inactive (active: false).)

I use vertical layout group, and it has a padding / spacing value. image

I also unchecked the Content Size Fitter to solve this problem.

hyunwoo9120 commented 1 year ago

I guess the scroll loop rect calculates content's height inaccurately.

qiankanglai commented 1 year ago

LoopScrollRect relies on calculating item size with LayoutUtility.GetPreferredHeight or LayoutUtility.GetPreferredWidth. So after applying the reproducing steps above, the cell height gets 200 here which is correct.

The problem in fact is cell has zero height after disabling Control Child Size

You can use other ways to adjust the real cell size (eg. setting cell prefab's height directly) and it just works.

hyunwoo9120 commented 1 year ago

Oh god I spent lots of time 😂 I finally solved. If I bother you I am sorry. I'd been focusing on solving this problem for over a week.

Even though it's written in the example, I thought that if I use my prefab's size (wxh) directly, I don't need the layout element of prefab.

But when I got the item size by getPreferredHeight at GetSize, it returned incorrect number. So I added the layout element to my prefab and checked preferred width and height, solved this...😂