Author Topic: NGUITools.AddChild Broken?  (Read 4325 times)

BlueSin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 17
    • View Profile
NGUITools.AddChild Broken?
« on: August 19, 2015, 03:30:37 PM »
Searched around a bit but I could not find anything for this issue.  I am using NGUITools.AddChild to instantiate a child UI game object in my current root.  But the instantiated game object is just an empty game object, also I noticed all the layers for my UI objects are empty for some reason?  First screenshot is of the empty game object that is being created, with an empty layer (also showing current existing layers), second screenshot is of the prefab that is supposed to be created, and lastly the code that is being used to instantiate:




  1. private void AddNavigation()
  2. {
  3.     NGUITools.AddChild(gameObject, NavigationPrefab);
  4. }

I have double checked the prefab assignment as well and it is correct so I am a bit confused about what is going on.  Any help is appreciated!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUITools.AddChild Broken?
« Reply #1 on: August 22, 2015, 02:03:37 AM »
The layer being unnamed simply means that you have a prefab referencing a layer that hasn't been given a name.

NGUITools.AddChild(parent, prefab) will indeed create a new instance for you. If you get an empty object then the "prefab" is either null, or it's not readable with Unity. Try dragging it manually via drag & drop. If you imported a Unity 5 prefab into Unity 4, it will not work for example.