Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Nemox · Aug 03, 2015 at 10:47 PM · classmonobehaviourfunctionsimplementationobject-oriented-programming

How exactly do Monobehaviour functions work?

So I've used functions like Awake, FixedUpdate, OnTriggerEnter and whatnot for some time now, but I'm not sure I fully understand how those functions work on a larger scale. I notice that they don't need to be tagged as "new" or "override". And it will compile and function properly regardless of whether one of these functions is actually implemented in a custom script.

What's going on with these functions, exactly? How do these built-in functions fit into the larger picture of object-oriented programming?

Comment
Add comment · Show 1
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 maccabbe · Aug 03, 2015 at 11:20 PM 0
Share

As far as I can tell, they don't fit in well with the concepts of C# because they are specific to Unity.

For instance, I've frequently heard monobehaviours without an Update method are faster than monobehaviours with empty Update methods. So it seems like monobehaviours without an Update function never have a Update called. This pretty much requires that $$anonymous$$onobehaviour functions behavior to be defined by Unity rather than something general to C#.

2 Replies

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

Answer by nisovin · Aug 04, 2015 at 12:32 AM

From what I understand, those are called using the message system in Unity. For example, by using GameObject.SendMessage or the other related methods (BroadcastMessage, SendMessageUpwards). I don't know exactly what the internal implementation of it is, but I've always assumed it's using some kind of reflection.

Comment
Add comment · Show 1 · 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 Nemox · Aug 04, 2015 at 03:43 AM 0
Share

Some great answers and comments from everyone. I also had a feeling it was the messaging system. I know a bit about reflection and invoking methods based on name, but I've heard reflection can be really slow.

I think for my own purposes I'll probably use virtual and override functions for the time being.

avatar image
1

Answer by ninjaboynaru · Aug 04, 2015 at 12:23 AM

I'm not 100% sure that this is how they work or that I fully understand your question, but this is how I would do it and it seems to be the most logical..

When an event happens in the Unity world, ie.(the game starts), Unity goes through each script in the game that is attached to a game object and calls the corresponding function for that event.

In this case, the corresponding function for the game/scene starting would be Awake() or Start(). The Update() function would correspond to the passing of a single frame.

Comment
Add comment · 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

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

25 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

Related Questions

The name '' does not exist in the current context 2 Answers

Creating a pointer variable to a GameObject inside a class that does not extend MonoBehavior? [C#] 2 Answers

Classic Class in C#? 3 Answers

Issues Inheriting classes and monoBehaviour 1 Answer

Referencing NON-monobehavior scripts - getting an error :/ 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