Author Topic: UIScrollView/UIGrid sorting (when set false) on NGUI.AddChild(parent, prefab)  (Read 5964 times)

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile

I'm presently using NGUI.AddChild(parent, prefab) to add instances under a UIScrollView/UIGrid. I'm noticing that the instanced objects are sorted alphabetically by name even though I've disabled UIGrid.sorted in the inspector. Instantiating objects myself under the UIScrollView/UIGrid did not have this issue. Please let me know how to keep them unsorted.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Unity sorts objects alphabetically in the project view, but the order in which they appear may not match the project view unless UIGrid's sorting is turned on.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
the problem is that the objects are showing up in the UIGrid sorted even though sorting is disabled. I can't seem to keep them in the order which I added them (to the UIGrid).
« Last Edit: January 21, 2014, 01:53:40 AM by ngui »

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile
I noticed that the UIGrid component gets disabled on play, not sure what is causing that and I don't receive any warnings or errors.

ngui

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 29
    • View Profile

So do gameobjects that go under the UIScrollView/UIGrid need to have the same name? otherwise it gets sorted by Unity?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
As I mentioned, hierarchy always sorts by name, but Unity doesn't do any sorting as far as I know. The order in which you add children is the order in which they will appear when you iterate through them. This implied run-time instantiation. Edit-time order is different, and varies from one platform to the next.