- Home /
Nested Prefab
How to instantiate prefabs as a child to another prefab(as parent)?? For example: I have one game object "G1" as prefab and other prefabs from "A" to "Z". how do i make these prefabs as a child to "G1" one at a time during runtime.
One more thing bugs my mind, should i make these "A" to "Z" child of "G1" in hierarchy and make "G1" as prefab. But, while instantiating "G1" only one outta "A" to "Z" get instantiated during runtime. like application running -> "G1 - B" instantiated, "G1 - R" instantiated.
If you resolve this with sample code that could me more helpful.
did you try changing parent of A-Z after instantiating it? http://docs.unity3d.com/ScriptReference/Transform-parent.html or http://docs.unity3d.com/ScriptReference/Transform.SetParent.html
smallbit has the correct approach. Instantiate the G1 prefab, then instantiate any of your A-Z prefabs, but just assign the A-Z prefab instance's parent to the instance of the G1.
@ smallbit : Why to change parent?? I mean A-Z has only one parent. Although thanks for the concern, appreciate it. Got the the answer.
@ supernat : I did exactly and got it. Thanks mahn!!
@suzil punk you first ask"How to instantiate prefabs as a child to another prefab(as parent)??" and "how do i make these prefabs as a child to "G1" one at a time during runtime" and than you are suprised upon my answer and ask "Why to change parent??" I am a little bit confused here If you are aware of what do you want. So to clarify you make an object A as a child of another object B only by changing objects B parent to object A. this is how it works.
Your answer
Follow this Question
Related Questions
A Question about applying changes to nested prefabs 0 Answers
Unity: How can you make a prefab immutable for instance overrides 0 Answers
Script is reading from prefab instead of instance 1 Answer
Reset script to prefab values 0 Answers
Two Instances of same Prefab dealing damage to each other. 0 Answers