Search Unity

Layout and Hierarchy Changes Via Script

Discussion in 'UGUI & TextMesh Pro' started by Thickney, Sep 1, 2014.

  1. Thickney

    Thickney

    Joined:
    Mar 3, 2013
    Posts:
    32
    I have a VerticalLayout set up with some entries and I want to be able to swap the positions of the entries fairly often. I noticed that just dragging an entry object in the scene view hierarchy automatically updates the positions nicely, but I don't see any way of doing this via a custom script? Is there anything available that would let me shift a transform up or down in a hierarchy?

    The only way I'm seeing of getting this to work with the new UI system is if I destroy all entries and instantiate the whole list in a different order whenever I need to do a refresh, which is horribly inefficient.
     
  2. JAKJ

    JAKJ

    Joined:
    Aug 17, 2014
    Posts:
    185
    Try the SiblingIndex functions inside Transform and see if it triggers layout updates.
     
  3. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    It would be great if the documentation for SetSiblingIndex said a bit more than "Sets the sibling index" too. ;)
     
  4. Thickney

    Thickney

    Joined:
    Mar 3, 2013
    Posts:
    32
    Thank you very much! I do all of my repositioning now with SetSiblingIndex and then disable/enable the VerticalLayoutGroup script so that it refreshes. It would be nice if the layout scripts could have basic properties like setting the group item index. It's kind of a black box right now, but I'll take it.