component.enabled

To my knowledge, setting the “enabled” property of a component is the recommended way to enable/disable it, and this is confirmed by the Unity3D tutorial on the subject.

So why isn’t “enabled” listed as a property on the Component reference page at Unity - Scripting API: Component ?

Enabled isn’t a property of Component, it’s only a property of certain classes that implement it. For example, you can enable or disable a Collider, but not a Rigidbody (which isn’t something that makes any sense to “enable” or “disable”…it’s always a Rigidbody).

–Eric

1 Like

Specifically, the Components that have an enabled property are derived from Behaviour.

Collider historically wasn’t a Behaviour because it didn’t always have an enabled property. I guess they forgot to change its parent class when they added it. Personally, I don’t think Behaviour is a useful class or a good name. Deriving from Component and an interface called Enableable, or similar, would work fine. Saying that for example Cameras or Colliders are Behaviours doesn’t make sense to me. The u in Behaviour also doesn’t do anything. :eyes:

1 Like

Thanks for the explanations, chaps. I see now the definition of Behaviour being “a component that can be enabled or disabled” (although I agree with Jessy - I think that’s a pretty terrible name to choose and not at all intuitive for certain component types!)