Author Topic: [Solved] UIGrid.Reposition() not working  (Read 4938 times)

Abnaxus

  • Guest
[Solved] UIGrid.Reposition() not working
« on: May 15, 2013, 05:14:38 AM »
Hi there,

I'm having a simple grid and when I remove an element, I'd like to Reposition() so I don't have blanks.
Problem is, when I Reposition dynamically, it doesn't work.
When I do from editor, it does.

So ... I really don't get those function working in editor and not dynamically....

If any of you have a suggestion, I'd love to hear it.

Thanks in advance.

PS: Here's the code executing the delete/reposition.
  1. public void DeleteReply(string index)
  2.         {
  3.                 GameObject temp;
  4.                
  5.                 for(int i=0; i < replies.Count; i++)
  6.                 {
  7.                         if(replies[i].mReplyObject.name.Contains(index))
  8.                         {
  9.                                 temp = replies[i].mReplyObject;
  10.                                 replies.RemoveAt(i);
  11.                                 GameState.Instance.mReplies.RemoveAt(i);
  12.                                 GameObject.Destroy(temp);
  13.                                 break;
  14.                         }
  15.                 }
  16.                
  17.                 mGrid.GetComponent<UIGrid>().repositionNow = true; (1)
  18.                 mGrid.GetComponent<UIGrid>().Reposition(); (2)
  19.         }

I tried with both (1) and (2) alone also.
« Last Edit: May 17, 2013, 09:01:46 AM by Abnaxus »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Bug ?] UIGrid.Reposition() not working
« Reply #1 on: May 15, 2013, 10:03:46 AM »
You need to use NGUITools.Destroy instead. Unity does not destroy immediately. If you have 10 children, and you destroy 5 of them, then check transform.childCount, it will still show 10. NGUITools.Destroy unparents the object so that transform.childCount shows the correct value.

Abnaxus

  • Guest
Re: [Bug ?] UIGrid.Reposition() not working
« Reply #2 on: May 17, 2013, 09:01:27 AM »
Thank you very much !

PS: So it means it just SetActive(false) until the object is totally released ?
Since it doesn't delete immediately, we should be able to see the object in scene, aren't we ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Solved] UIGrid.Reposition() not working
« Reply #3 on: May 18, 2013, 05:53:28 AM »
Deletion is delayed until the end of the frame. Not sure where you got SetActive from.

Abnaxus

  • Guest
Re: [Solved] UIGrid.Reposition() not working
« Reply #4 on: May 21, 2013, 07:24:07 AM »
If it's delayed, we should be able to see the object until it's removed, don't we ?

And since I can't see the object, but it is still counted in the code, I wondered if until the end of the delay, the object was put Inactive (with SetActive).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [Solved] UIGrid.Reposition() not working
« Reply #5 on: May 21, 2013, 12:58:12 PM »
Object's active state has nothing to do with the object remaining in the hierarchy. You can have disabled objects, but they still belong to a hierarchy.