How to instantiate an object into a Hierarchy

So say I have a model with a body, a head, and a nose, 3 meshes.
And the body has 4 bones.

The Hierarchy would look something like this:

So how would I destroy that Head model, and instantiate another head model in it’s place in the hierarchy?

I know I could simply just instantiate a prefab with the nose already a child of the head, but it’s the theory of destroying and instantiating meshes in and out of a hierarchies that puzzles me.

If you want to see my problem more in-depth then look here: http://forum.unity3d.com/threads/71273-Maintain-Hierarchys-question?p=455676#post455676

Also, is it possible to download the scripting reference anywhere? I have limited net access.

My last two posts have gone unanswered, and before that I got one incorrect answer. Seems to me like this forum is going to hell. Anyway, thanks for reading :]

Then I will try to answer, and correctly at that! :slight_smile:

Well, then you’ll want to take advantage of the transform.parent property. I do this in many of my scripts.

Suppose you wanted to replace the head. A simple sequence would be:

(1) instantiate a NewHead GameObject
(2) Setup NewHead’s parent, eg set NewHead.transform.parent = bn_Head.transform
(3) Setup NewHead’s children, eg set Nose.transform.parent = NewHead.transform
(4) finally, delete the old Head GameObject

v

In Unity Editor, go to Help Menu. The manual and references are installed with unity.

In Unity (at least, in Unity 3 desktop and Unity 1.7 iPhone Advanced) if you click on Help | Scripting Reference you will acess the offline version (look at the URL to see exactly where it is on your systems).

It’s… fairly large, I wouldn’t recommend killing a forest to print it.

[ Edit: AzulValium beat me to it. Oh well… overanswered is better than no answers. :slight_smile: ]

I wouldn’t recommmend destroying the object if you are doing a character selection. I think I would likely change the mesh and material.

Thanks for the replies guys they’ve been really useful, it’s nice to see I’m wrong about the forum going to hell :stuck_out_tongue: hehe

Iceshaft what method would you recommend for removing objects from the scene/hierarchy? I’m instantiating prefabs so I assumed there’d be no repercussions from destroying the instances.