7
\$\begingroup\$

Is it possible for one prefab to contain multiple game objects, preferably in a parent-child relation. I am making a complex enemy that I want to separate into a couple of game objects with separate sprite renderers, scripts and other parameters. This would simplify the code I need to write for each of the elements. I know I can create one (the parent) object, and then instantiate the others in the Awake() or Start() methods, but I'm asking if there is a way to create a prefab that would contain all of the necessary elements (so I can create the entire thing with one Instantiate() call.

Thanks

\$\endgroup\$
  • 3
    \$\begingroup\$ I was under the impression that making a prefab out of the parent object retains all the children in the prefab. i.e. an archer prefab may be made up of the character and the bow objects, each with their own properties and children (if needbe). As long as you have the one containing parent object, it should do what you want? Or so I thought (please correct if otherwise) \$\endgroup\$ – nickson104 Nov 12 '15 at 8:28
6
\$\begingroup\$

As already commented, creating a prefab with one or multiple child objects works without any modification. But keep in mind - if you delete one or many child(ren) it will break the instantiated prefab's connection to the prefab. Once the connection is broken, changing the prefab will not apply to the instantiated prefabs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.