Author Topic: Instantiate prefab activates all children objects  (Read 6260 times)

Jose

  • Guest
Instantiate prefab activates all children objects
« on: May 31, 2012, 06:30:28 AM »
Hi!
I have a complex NGUI object which consists of UI Root object > Camera object > Anchor object > Panel objext > all my objects. I developed it in the other project. Not all of children objects are active at start, but when I put this prefab into my main scene and execute command
Instantiate(Terminal,new Vector3(0,0,0),Quaternion.identity);
it activates all children! What should I do to make inactive objects remain inactive at start?

Thank you!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Instantiate prefab activates all children objects
« Reply #1 on: May 31, 2012, 07:33:54 AM »
You can't. That's just how Unity works -- when you instantiate a prefab, it will activate all of its children. it doesn't remember inactive state of game objects because all game objects are inactive while they are on a prefab. It will remember the inactive state of scripts, however.

I suggest splitting your UI into several prefabs that get instantiated when needed instead.

Either that or find a way to not have to instantiate that prefab -- by already having it in your scene, for example. You can also put that prefab into another scene, and load that scene via LoadLevelAdditive.

Jose

  • Guest
Re: Instantiate prefab activates all children objects
« Reply #2 on: May 31, 2012, 09:29:25 AM »
I can't have all prefabs in scene at one moment - it'll be too large((( First I tried to place these NGUI objects into my scene and to switch between Cameras, disabling/enabling them with their children. But it takes to much memory. I'll try LoadLevelAdditive, thanks a lot!

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Instantiate prefab activates all children objects
« Reply #3 on: May 31, 2012, 12:11:45 PM »
Split your UI up into multiple prefabs and load the ones you need.

Make an "empty" heirarchy with a your root, anchors etc in, and then add your screens individually as you need them, for instance.