Author Topic: Need some advise about Instantiate/AddChild  (Read 3577 times)

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
Need some advise about Instantiate/AddChild
« on: October 25, 2012, 10:57:59 PM »
Hi guys
I'm going to build a embedded chat scene
---------------------------------------------------------
ScrollableMessages
      |---Message(prefab)
      |         |-- A Label and a sliced sprite
      |---Message(Clones)
---------------------------------------------------------
The program may call thousand times of NGUITools.AddChild().
Is AddChild equals to Instantiate? Will it cost too much?

Because I was told instantiate/destroy is very expensive,
and we'd better don't call it too many/often on mobile device.
People also suggest me to use a pool instead.

But I have no idea how to make it work with UITable/UIGrid :p
« Last Edit: October 26, 2012, 02:07:30 AM by alexlange »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Need some advise about Instantiate/AddChild
« Reply #1 on: October 26, 2012, 01:24:10 AM »
Yes, AddChild does an Instantiate call. I suggest you cache these instead. Enabling / disabling them (and/or reusing them) instead will have the same effect, but will be faster.

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Need some advise about Instantiate/AddChild
« Reply #2 on: October 26, 2012, 02:07:15 AM »
Understand
Thank you Aren  :D