Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by OfficerSugar · Jan 12, 2018 at 03:48 PM · componentcomponentsmeshfilterenabledreference assemblies

.enabled not working

 MeshFilter nem = ne.GetComponent<MeshFilter>();
 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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Bunny83 · Jan 12, 2018 at 04:06 PM

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?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OfficerSugar · Jan 12, 2018 at 04:09 PM 0
Share

I've never realised that meshfilter doesn't have a checkbox in the inspector, this makes so much more sense now! thank you for an another great answer mr. bunny!

avatar image Tom-Mensink OfficerSugar · Jan 12, 2018 at 05:07 PM 0
Share

Disabling $$anonymous$$eshRender is indeed the way to go, e.g.:

public static void SetActive$$anonymous$$eshRenderers(this GameObject gameObj, bool isActive)
{
        foreach ($$anonymous$$eshRenderer child in gameObj.GetComponentsInChildren<$$anonymous$$eshRenderer>()) // GameObject recursive call, including this gameobject
        {
            child.enabled = isActive;
        }
}

avatar image
2

Answer by pako · Jan 12, 2018 at 04:09 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jan 12, 2018 at 05:10 PM 1
Share

Though what many people confuse is that there are other built-in components which are not derived from Behaviour but do have an enabled property. Renderer and Collider define their own enabled property. Unfortunately since those enabled properties are not the same they can't be treated in a generic way. Though if you want a flat class hierarchy you have to live with such reimplementations of the same concept. $$anonymous$$aybe one day Unity implements some common interfaces which the built-in components implement (like an IEnableable which however is a horrible word ^^)

avatar image pako Bunny83 · Jan 12, 2018 at 05:37 PM 0
Share

Good points!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does .SetActive work with components? 1 Answer

'UnityEngine.Component.active' is obsolete. 4 Answers

2D Animation does not start 1 Answer

BCE0019: 'enabled' is not a member of 'UnityEngine.Component'. ??? 2 Answers

Depth of field not working 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges