Author Topic: UIButton stops responding after NGUITools.AddChild  (Read 3783 times)

hazzy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 5
    • View Profile
UIButton stops responding after NGUITools.AddChild
« on: February 06, 2013, 09:23:53 PM »
Hey all,

I have a UIDraggable panel with a UIGrid that has UIButtons added and removed from it based on certain events.

I have made a prefab that contains everything I want from that button (background, text label, sprite checkbox, etc). This prefab works perfectly if I drag it by hand to the grid in my scrollable panel. However, when I add it using NGUITools.AddChild and pass the grid and the prefab name, the button simply stops working. Hover/pressed colors don't change, OnClick() doesn't fire, etc. Is there a workaround for this or am I missing something?

Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton stops responding after NGUITools.AddChild
« Reply #1 on: February 06, 2013, 10:27:22 PM »
When you use AddChild, the object you are instantiating assumes the game object layer of the parent.

Make sure it's what you expect it to be.

hazzy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 5
    • View Profile
Re: UIButton stops responding after NGUITools.AddChild
« Reply #2 on: February 07, 2013, 10:19:28 AM »
Thanks! Worked like a charm. The Grid GameObject was moved to DefaultLayer instead of my NGUI layer and moving it back worked perfectly.