Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by pickle chips · Sep 14, 2014 at 06:10 PM · uiguigrid4.6

Sorting the children of a Grid Layout in 4.6 UI

Hi. So I'm making a quest log. Once I quest is started, I need to add it to the active section of the quest log, which is a Grid Layout. The only problem is, this adds it at the bottom of the list. I want it to be added to the top so the most recent quests appear first. How can I arrange the elements of the grid layout through script? Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by chilemanga · Dec 21, 2017 at 02:27 PM

There's a solution that's better performant than de-parenting the UI elements and then parenting them again in the required order, which is using the SetSibling methods from the Transform.

SetAsFirstSibling: Move the transform to the start of the local transform list. SetAsLastSibling: Move the transform to the end of the local transform list. SetSiblingIndex: Sets the sibling index. https://docs.unity3d.com/ScriptReference/Transform.html

So, in your case, when a quest becomes active you just need to set that quest object as the first sibling. You can find more info in this thread: https://forum.unity.com/threads/order-of-elements-in-layout-groups.267668/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Dec 21, 2017 at 03:18 PM 1
Share

This should be the answer. You can make a sorting worker function with these to get the desired behavior.

avatar image
1

Answer by DoomSamurai · Dec 04, 2014 at 12:15 AM

You need to de-parent your ui elements, sort them (in a List or Array) and then re-parent them to the GridLayout transform in the sorted order. Remember that for UI elements you need to use Transform.SetParent to set the parenting.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chilemanga · Dec 21, 2017 at 02:28 PM 0
Share

This is a good solution, but there's some set sibling methods that performs better and will avoid to lose some FPS. Please, check my answer below.

avatar image
0

Answer by orb · Sep 14, 2014 at 08:14 PM

It depends on what the object holding the list of quests is, but if it's just a plain List why not simply use list.Insert(0, item) when you add it to put it first?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

v4.6 UI Element's Positioning Incorrect 1 Answer

(4.6 UI) How to set up a window with x buttons, with a scroll bar? 1 Answer

New 4.6 UI question: How do you resize a panel relative to the screen but remain height/width constrained? 5 Answers

Unity 4.6B UI Scrollbar Usage 1 Answer

Grid Layout Group leaking outside canvas. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges