Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Cheong on September 10, 2015, 02:58:11 AM

Title: Add Child On UIGrid problem: Arrangement is wrong
Post by: Cheong on September 10, 2015, 02:58:11 AM
Hi readers,

I am using NGUItools.AddChild(Parent, Prefab).

But when I was trying to add prefabs into the parent with array conditions, the arrangement seems to go wrong(the last object was added into the parent first instead of the first object).

Here the example code of how I do it:

public GameObject parent;
public GameObject prefab;

for(int i = 0; i<TotalNumberOfObjects; i++)
{
NGUItools.AddChild(parent,prefab);
prefab.name = "Object" + i;
}

The list of the prefabs added into the parent are as listed such as below:
1.)Object5;
2.)Object1;
3.)Object2;
4.)Object3;
5.)Object4;

Can you help me resolve this? Am I doing something wrong instead?

Thanks.
Title: Re: Add Child On UIGrid problem: Arrangement is wrong
Post by: Holy Manfred on September 10, 2015, 12:56:31 PM
I don't think this i a NGUI issue. I am not sure, but the order of children as it is displayed in the scene hierarchy in the editor might not necessarily be the same as Unity's internal order of the children. You could keep track of your children in a separate list or use them in another way so you do not have to rely on whats visible in the scene hierarchy.
Title: Re: Add Child On UIGrid problem: Arrangement is wrong
Post by: devomage on September 10, 2015, 02:25:56 PM
your code looks fine.  try adding reposition after your loop...

  1. grid.Reposition();
  2.  
Title: Re: Add Child On UIGrid problem: Arrangement is wrong
Post by: ArenMook on September 13, 2015, 05:52:27 AM
Note that the sorting is alphabetic, not alphanumeric. Ie:

Object1
Object10 <-- note where this will end up
Object2
Object3
Object4
...etc

You need to name them like so:

Object01
Object02
Object03
...
Object09
Object10
Title: Re: Add Child On UIGrid problem: Arrangement is wrong
Post by: Cheong on September 22, 2015, 10:41:06 PM
Ok, just saw this replies recently... not sure why I didn't noticed.
Problem solved btw, Thanks!