Instantiate object as child of a clone

Hello, how can I instantiate an object as child of a clone? I need to instantiate the first object and then instantiate another object as child of the previously instantiated object, how can I do that ?

Instantiate method has overload accepting transform instance to set it as parent of instantiated object. So you just need to instantiate first object and then call that overload with first object’s transform.

var first = Instantiate(prefab1);
var second = Instantiate(prefab2, first.transform);
2 Likes

What @palex-nx said is spot-on… I would only add that I suggest using the templated version of Instantiate:

var first = Instantiate<GameObject>(prefab1);
var second = Instantiate<GameObject>(prefab2, first.transform);

As an aside and completely unrelated to your problem, I also strongly suggest never using Resources.Load(); Instead use Resources.Load(); so that if you have two assets named the same (such as a texture and a material), you will consistently get what you intend rather than having it sometimes cast to a null.