- Home /
How To Dynamically Remove Scroll Rect Content
I have a Scroll Rect with a movement type of Clamped that has a bunch of images as content. I have seen forums explaining how to dynamically add content, but how do you dynamically remove content and have the content clamp to the correct position?
For example, here is my Scroll Rect and image filled content:
I can easily write code to destroy the game object of the first image, but it leaves it like this:
Is there any way to remove that first object and have the rest of the objects clamp to the left side? I tried writing code to do it, but was struggling, so I would appreciate any help!
Answer by mattmjarvis · Apr 10, 2019 at 08:01 AM
@shmoji Try attach a component to your content object (Or the object that is containing your images) called 'Horizontal Layout Group'. This will automatically lay out your objects depending on how you set up the component. Seeing as it's in a scroll rect - I would also advise to use this in conjunction with the 'Content Size Fitter' component. Which will resize the scroll view content object based on the size of it's children; this will resize it to bet fit your children rather than having an empty scrolling gap and the end when they reposition after one gets removed.
https://docs.unity3d.com/Manual/script-HorizontalLayoutGroup.html https://docs.unity3d.com/Manual/script-ContentSizeFitter.html
Your answer
Follow this Question
Related Questions
ScrollRect is slowing down, when scrolling many (same) images placed in Grid Layout Group 0 Answers
Scroll rect snaps everytime with drag 0 Answers
[Solved] need help regarding autolayout in scrollrect 1 Answer
Scrollable zooming list 0 Answers
how to make UI Image inside Scroll Rect (ScrollRect) autoscroll? 1 Answer