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 /
  • Help Room /
avatar image
1
Question by edincanada · Feb 02, 2017 at 05:19 PM · componentinterfaceenabledbehaviour

Why isnt the enabled property part of an interface?

Is there any known rationale to not having the enabled property of some bheaviours and components not abstracted in an interface?

I'd very much like to be able to create an array that can can contain renderers, ridigbodies, behaviour, etc knowing they all implement some "IEnable" interface, meaning they all have an enabled interface.

 //Dream example:
 List<IEnable> enableList ;
 enableList.Add( rendererObj) ; //renderers have the enabled property
 enableList.Add( ridigBodyObj ) ; // ridigbodies do too.
 enableList.Add(scriptObj) ; // and so do scripts.
 //and a few more I can't recall right now.
 foreach( var current in enableList ) current.enabled = false ;

If you are thinking the Component class can do the trick, It can't. It does not have an enabled interface.

Disclaimer: This is a software design question. This is not a question meant to solve an immediate practical problemn. It is meant to fill a knowledge gap, and hopefully be accessible thru this website to anyone that may use such knowledge for a more practical purpose.

Comment
Add comment · Show 5
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 hexagonius · Feb 02, 2017 at 05:55 PM 0
Share

maybe because nobody thought that disabling each component single handedly ins$$anonymous$$d of disabling the whole gameobject, basically being the same for all components, would make sense. maybe there's also performance considerations involved.
but to be honest, an engine engineer would have to answer this to be sure.

avatar image Owen-Reynolds · Feb 02, 2017 at 05:57 PM 1
Share

Opinion/Discussion Qs are better in the Forums. I'd specify whether you want a work-around. $$anonymous$$ight also look for an official Unity FeatureRequest.

$$anonymous$$y opinion: it's a matter of perspective. $$anonymous$$any native C#/Java users think there should be an interface for everything that can have one. $$anonymous$$y feeble software engineering is from Stroustrup, who says you shouldn't make things you only think there might be a use for.

avatar image Bunny83 Owen-Reynolds · Feb 02, 2017 at 06:29 PM 0
Share

Right, even the property has the same name, it's actual function differs from case to case. Not all Behaviours can be enabled that's why the Behaviour class as well as the Component class does not have an enabled property. You could go crazy with all possible properties, like "color" or "texture".

avatar image edincanada Bunny83 · Feb 02, 2017 at 06:48 PM 0
Share

Technically (perhaps pedantically) speaking, all behaviours have the enabled property. https://docs.unity3d.com/ScriptReference/Behaviour.html

$$anonymous$$oreover, I cannot think of any component with the enabled property that does not conceptually do the same in each case (very much expected behavior every time). Colliders stop colliding, scripts stop running Update(), RigidBodies stop interacting with physics, renderers stop rendering.

avatar image edincanada · Feb 02, 2017 at 06:26 PM 0
Share

Wanting to disable and enable "enableable" features within a game object without needing to know their concrete type. That example I gave is a possible use case, it should not take much imagination to see how this use case would appear in a real project.

If you have a frozen character, and there is an event that 'enables' its rigidbody, a script that lerps a glow, a particle effect, an animator component, and an audio source, a collider. $$anonymous$$aybe an event is supposed to trigger them all. Not only would an interface make the code cleaner, but It would make it extensible (Open/Closed principle).

$$anonymous$$aybe it should indeed be in the forums. it is more of a discussion thing.

0 Replies

· Add your reply
  • Sort: 

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

65 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

Related Questions

On Renderer Was Enabled? (C#) 0 Answers

random occuring NullReferenceException 1 Answer

Disable a C# script from another C# script. 1 Answer

How to custom inspector with dynamic options (e.g. Light Component) 1 Answer

Change the state of a GameObjects Child using an Abstract Class with an Interface 1 Answer


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