Scroll view with newest items on the top instead of the bottom?

Newbie here, with probably a newbie question.

So, I followed through and completed the Scroll view tutorial here:

I now have a good scroll view with a list of buttons.

My problem is though, when I add buttons to the new list, it adds the buttons to the end of the list. My goal is for the buttons to be added at the top of the list, so that the newest object added to my scroll view is placed at the top of the list.

Please help if you can. I can’t find anything online about this. Thanks.

1 Like

Are you using some layout? Vertical/grid?

With vertical, I’m pretty sure you can use: Unity - Scripting API: Transform.SetAsFirstSibling
(or lastsibling, if I got that mixed up)

I tried your scenario with 1 column grid view, and accomplished adding new buttons to the top of the content with the settings: Start Corner: lower left, Alignment upper left. (constraint = 1).
But I don’t know if there’s more to what you’re doing than what you described. :slight_smile:

1 Like

Sorry, could you possibly show me visually what it is you did? I’m not sure what you’re describing yourself doing.

And yeah, so basically there are two scroll view lists, each with buttons as the items in the list. when I click on a button in one list, it transfers over to the other scroll view.

My problem is that right now when it is added to the other list, it is added to the END of the list. I want the newest to be added to the top.

The first suggestion/option I gave is just a line of code when you add the button.

The other option is the grid layout component. All I did was describe a few of the settings you see on it, that I used to put the buttons at the top when added.
Not sure how else to explain it…Let me know if something didn’t make sense.

What methos describes is how you’d generally handle this, but I don’t think the tutorial code is set up that way.

Try using ‘Insert’ instead of ‘Add’ in the AddItem method, that will add the item to the front of the list.

void AddItem(Item itemToAdd, ShopScrollList shopList)
{
    shopList.itemList.Insert(0, itemToAdd);
}

Cool - if that works, I’m glad.

Ah, I see…when I clicked the link you posted, I only skimmed through the video and didn’t even see the code or realize it was a 9-part series lol. So, that’s my bad – sorry :slight_smile:
At first, I thought you had just watched a basic video and expanded the concept all on your own, and the ideas I suggested were very “general/vague” (not specific to the video at all).

Hopefully that new code works well for you.

No code required. This is very helpful. UI Scroll View automatic Content height « Unity Coding – Unity3D