Search Unity

Question Make Vertical Layout Group always shift items from the bottom?

Discussion in 'UGUI & TextMesh Pro' started by Josiah_Ironclad, Jul 19, 2021.

  1. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    Title and video pretty much say it all. I have a Vertical Layout group inside which I have some items. When I click on one, it gets moved to another VLG. The first VLG moves the other items in itself to prevent a gap from forming. But it seems to do so in a random direction.

    I did everything really quickly to save up on file size (originally made the video for Discord usage).

    When an item is removed, the VLG seems to randomly pick either the top or bottom half of all the items to shift into the removed item's position, regardless of where the removed item is in the visible part of the parent (I'm using a mask), or any other criteria, like how many items there are (above 4). I want it to always shift the items from below the removed item, upwards.

    I've been sitting on this for a couple days, and I can't come up with what to do. T̶h̶o̶u̶g̶h̶ ̶I̶ ̶s̶t̶i̶l̶l̶ ̶h̶a̶v̶e̶n̶'̶t̶ ̶t̶e̶s̶t̶e̶d̶ ̶w̶h̶e̶t̶h̶e̶r̶ ̶t̶h̶e̶r̶e̶'̶s̶ ̶a̶ ̶l̶i̶n̶k̶ ̶b̶e̶t̶w̶e̶e̶n̶ ̶t̶h̶e̶ ̶n̶u̶m̶b̶e̶r̶ ̶o̶f̶ ̶c̶h̶i̶l̶d̶r̶e̶n̶ ̶b̶e̶i̶n̶g̶ ̶o̶d̶d̶ ̶o̶r̶ ̶e̶v̶e̶n̶,̶ ̶a̶n̶d̶ ̶t̶h̶e̶m̶ ̶b̶e̶i̶n̶g̶ ̶s̶h̶i̶f̶t̶e̶d̶ ̶u̶p̶ ̶o̶r̶ ̶d̶o̶w̶n̶.̶
    Edit: There isn't a link.

    TL;DR: When I remove an item, I only want items below it to shift upwards, but sometimes items from above shift downwards.
     
    Last edited: Jul 20, 2021
  2. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    I found out the issue never occurs when the first item in the ScrollRect is visible. But I still have no clue exactly which script and method is responsible for this behaviour.
     
    Last edited: Jul 21, 2021
  3. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    Bump. Still have no idea how to do this.:(
    It seems to be how pretty much all RPGs with a list type inventory do it, so you'd think there'd be some documentation on it in some obscure blog at least.
     
  4. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    197
    Hello, did you manage to solve your issue? can you provide a minimal unity package to test it ?
     
  5. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    No, sorry. And I've moved onto other projects for now.
     
  6. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    197
    Np, good luck