- Home /
Why does Collider derives from Component instead of Behaviour ?
Hello there !
As the title says, I would like to know why Collider derives from Component instead of Behaviour, since it has an enabled property. Isn't the difference between Component and Behaviour the fact that a Component is not disableable while a Behaviour is ? Or did I misunderstand API's architecture ?
Thanks in advance for your answers :)
(yeah, that question is useless, I'm just being curious :)
Components can be disabled. It is the same as unchecking them in the inspector view.
Nope, the doc is quite clear about that.
No enabled property in Component (Transform is a typical component) : http://docs.unity3d.com/Documentation/ScriptReference/Component.html
It is clearly stated that Behaviour differs from Component because they can be disabled : http://docs.unity3d.com/Documentation/ScriptReference/Behaviour.html
Considering this, I have difficulties understanding why Collider derives from Component, but there has to be good reasons :)
Answer by Bunny83 · Jun 26, 2013 at 02:34 PM
It's more a conceptual thing. A Behaviour is usually an active component that controls the Behaviour of the GameObject. A Collider is a passive Component. It doesn't do anything. It's just "used" by other active Components like the Rigidbody.
I know the Rigidbody isn't a Behaviour either, but i guess it was a compromise since a Physics object can't really be disabled. Even as kinematic Rigidbody it's still an active component.
The class hierarchy might not be perfect, but i guess behind every decision they made there's at least some kind of reason / sense ;)
Well, I guess that make sense, thanks for your answer :)
It's also important to note that Components do not receive any of the events such as OnCollisionEnter, OnEnable, etc.
I've found that it's easier to wrap your head around when learning Unity to understand that a Component is the most raw form of an object that can be attached to a GameObject, and that it really exists as a layer below and beside your implementation code that allows you to communicate with the engine.
In almost all cases (except very advanced), there is no reason for your implementation to derive from Component directly, as a $$anonymous$$onoBehaviour is a Component inherently, and $$anonymous$$onoBehaviours have access to all of the engine's messages which are vital to the game logic.
Actually, I don't think it's even possible for the user to attach a custom non-$$anonymous$$onoBehaviour based component.
Yes you are correct. For a time I thought that was possible if you were integrating some low-level plugin but it definitely appears to have some system-level safeguard there preventing it from even happening.
Your answer

Follow this Question
Related Questions
Performance: Addcomponent BoxCollider in update method 0 Answers
Generic way to get properties on Component? 3 Answers
2D Animation does not start 1 Answer
Internal collisions 1 Answer