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
0
Question by durga-sundeep · Sep 26, 2019 at 05:36 AM · monobehaviournon-monobehavior

why non-Monobehaviour classes cannot be attached as a component in Unity3D?

Classes that are not inheriting from Monobehaviours cannot be attached to a Gameobject as a component. Why is it? What is Monobehaviour exactly?

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

1 Reply

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

Answer by Mouton · Sep 26, 2019 at 05:24 PM

MonoBehaviour inherits from the Behaviour class which inherits from the Componentclass to extend its functionalities.


Component

It is the base class for everything that can be attached to a GameObject.

It implements component related stuff such as GetComponent methods.


Behaviour

A component that can be enabled or disabled, it does not implement anything else.


MonoBehaviour

It is the base class for every scripts. It implements some basic method, such as Invoke and Coroutine handlers. It also implements all the messages (event methods) Unity calls internally.


You can create a class which inherit from Component, but it won't receive Start, Update, and such messages and you won't be able to enable/disable it. By inheriting from Behaviour, you can enable/disable your component, yet it does not have much effect since this is mostly useful for the event methods. It is very uncommon to inherit directly from these classes but you can do it if you need an object which just need to use GetComponent and such methods.

Comment
Add comment · Show 3 · 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 durga-sundeep · Oct 09, 2019 at 10:18 AM 0
Share

@$$anonymous$$outon Thanks a lot for the answer :-)

I have a doubt. Like what is the software architecture used to build Unity3d.

avatar image Bunny83 durga-sundeep · Oct 09, 2019 at 10:43 AM 0
Share

I'm not sure what you question is about or why this is relevant. However Unity is actually written in C++. They only use C# / .NET for the managed scripting side. And no, you can not and should not derive any of your classes from Component or Behaviour. Only $$anonymous$$onoBehaviour (a behaviour written in $$anonymous$$ono / C#) can be used as base class for custom components. Note that every UnityEngine.Object derived class has a C++ counterpart. $$anonymous$$ost of the functionality is actually implemented on the native C++ side. The C# code consists mainly of wrapper classes.

avatar image durga-sundeep Bunny83 · Oct 11, 2019 at 04:03 AM 0
Share

thanks a lot @Bunny83 :-) ... this is very informative.

All I was trying to ask was ... like does unity3d is built on ECS architecture. I know that they have introduced ECS in Unity for better performance of the games built with Unity. So, my question is that is Unity3D is built on ECS architecture (software architecture)?

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

114 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 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

Accessing a MonoBehaviour List within a Non-MonoBehaviour Script 2 Answers

Is it possible for a non-MonoBehaviour class to use built-in functions? 1 Answer

MonoBehaviour methods in non-MonoBehaviour class 1 Answer

How to use GetComponent in Non-Monobehaviour script? 2 Answers

How do I detect that MonoBehaviour is modified in the Editor? 2 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