.enabled not working

MeshFilter nem = ne.GetComponent();
nem.enabled = false;

So i’m trying to disable a MeshFilter Component but Unity gives me an error that points to “.enabled” and says

“error CS1061: Type UnityEngine.MeshFilter' does not contain a definition for enabled’ and no extension method enabled' of type UnityEngine.MeshFilter’ could be found. Are you missing an assembly reference?”.

I don’t get it, every component should work with .enabled, what’s wrong?

Uhm, no. Not every component can be enabled or disabled. Only those which actually have a checkbox in the inspector. The Component base class does not have an enabled property. The Behaviour subclass does have one. There are many components which can not be disabled and MeshFilter is one of them. It also wouldn’t make much sense as the MeshFilter only holds a Mesh reference. It doesn’t do anything. You may want to disable the MeshRenderer?

No, a Component does not have an enabled property. A Behaviour which inherits from Component defines the enabled property. And of course all Behaviour subclasses also inherit the enabled property, e.g. MonoBehaviour.

However, a MeshFilter inherits from Component, not Behaviour, and that’s why the enabled property is not available.