transform.active question - Model Mesh Scripting

I have a fully animated orc model with a sword.

The sword is a Child mesh deep within the hierachy of the model itself.

Now I want the orc to start the game without his sword. If i click down the models hierachy I can simply click the box and disable the mesh. But.. now I want to do this in code.

So.. i used this:

Private Transform Sword;
Private bool isSwordActive;

Start()
{
   isSwordActive = false;
   Sword = transform.Find("Sword");

   if (isSwordActive)
   {
      Sword.active = true;
   }
   else
   {
      Sword.active = false;
   }
}

Now this has generated a ton of errors, from null ref errors to the entire model not animating anymore, to the model not updating at all again. Also got an error saying something like "the .active property is redundant."

Can anyone tell me how to disable parts(s) of a models meshes in code?

If you just want to make it invisible, you just want to disable the renderer component of that object.

Do it like this:

(also note the change in case - the convention is to use lowerCase for variables, UpperCase for function names and classes)

private Transform sword;
private bool isSwordActive;

Start()
{
   isSwordActive = false;
   sword = transform.Find("Sword");

   if (isSwordActive)
   {
      sword.renderer.enabled = true;
   }
   else
   {
      sword.renderer.enabled = false;
   }
}

And yes, the "active" property is used on GameObjects themselves, to activate and deactivate them (so that they are effectively remove entirely from the scene), whereas the "enabled" property relates to components which are attached to GameObjects, allowing you to enable or disable various aspects of the GameObject.

Thanks, thats great!

I can ducktape the code from there. But what if I do want to remove the entire sword? It would make the combat collision code with that object alot easier since it would only be active when the actual gameObject is. Right?