Author Topic: NGUITools.AddChild UIButton Message Target Issue  (Read 2652 times)

Bissmark

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
NGUITools.AddChild UIButton Message Target Issue
« on: December 19, 2013, 06:57:29 PM »
Hi
So I am creating a menu system. I have an object where when selected creates a new panel which an existing prefab. I have the UIButton Message script attached to the prefab because I want this new panel to be part of the other menu options.

The issue I am having is that I cannot attach my UI Root as the target in the UIButton Message script because the Panel is not in the heirachy because it is a prefab that gets "instantiated" during runtime.

I have spent a couple of days wrapping my head around it with no avail and was hoping somebody here could help me
Thank you

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddChild UIButton Message Target Issue
« Reply #1 on: December 20, 2013, 12:18:39 PM »
That's how Unity works. You can't save referenced to objects outside the prefab. You have to find the object by some other means after the prefab has been instantiated. Finding it by name is the slowest approach. Finding it by tag is faster. Finding it by having a singleton script attached to it with a public "instance" accessor is the fastest approach.