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 RayAndGames · Sep 25, 2019 at 11:30 AM · programmingmethodmessages

Cannot make void Awake() or any MonoBehaviour's Messages,I can't call void Awake()

My IDE doesn't suggest me any MonoBehaviour's messages such as Awake(), or OnCollisionEnter(). Do I have to type them manually?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DetectCollision : MonoBehaviour
 {
     // Start is called before the first frame update
     void Start()
     {}
 
     // Update is called once per frame
     void Update()
     { }
     
     void Awake()
     { }
 
     void OnCollisionEnter (Collider other)
     {}
 }

,It's quite simple, my IDE cannot detect or suggest me void Awake() or void OnCollisionEnter() even though I can use MonoBehaviour's other public method.

====

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DetectCollision : MonoBehaviour
 {
     // Start is called before the first frame update
     void Start()
     { }
 
     // Update is called once per frame
     void Update()
     {}
     
     void Awake()
     {}
 
     void OnCollisionEnter (Collider other)
     {}
 }

Those methods up there, I typed them manually. How do I fix this?

Comment
Add comment · Show 4
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 RayAndGames · Sep 25, 2019 at 02:29 AM 0
Share

It actually works, I can type them manually and it still works. Now, why the heck doesn't IDE suggest me those super helpful messages?

avatar image Mouton · Sep 25, 2019 at 01:00 PM 0
Share

What is your IDE ? Do you know if it has any Unity support at all ?

The only editors I know that are aware of Unity components are Jetbrain's Rider and $$anonymous$$icrosoft Visual Studio.

$$anonymous$$ost of editors don't have support for Unity, even if they can get symbols from UnityEngine and UnityEditor library, they won't tell you about "Event" methods (or "$$anonymous$$essages") and thus won't be able to auto-complete it for you. This is because how the $$anonymous$$onoBehaviour class is conceived, these methods are not abstract or overridables as you would think: they don't exist at all in the class. Unity uses messages (https://docs.unity3d.com/ScriptReference/GameObject.Send$$anonymous$$essage.html) to trigger event function so that if the method does not exist, it won't crash the program.

avatar image Hellium Mouton · Sep 25, 2019 at 01:38 PM 0
Share

No, Unity does not use Send$$anonymous$$essage (nor reflection) in order to call the "magik functions" (awake, start, update, ....)

Ins$$anonymous$$d, the first time a $$anonymous$$onoBehaviour of a given type is accessed the underlying script is inspected through scripting runtime (either $$anonymous$$ono or IL2CPP) whether it has any magic methods defined and this information is cached. If a $$anonymous$$onoBehaviour has a specific method it is added to a proper list, for example if a script has Update method defined it is added to a list of scripts which need to be updated every frame.

During the game Unity just iterates through these lists and executes methods from it — that simple. Also, this is why it doesn’t matter if your Update method is public or private.

Sources : https://blogs.unity3d.com/2015/12/23/1k-update-calls/

avatar image Mouton Hellium · Sep 25, 2019 at 01:47 PM 0
Share

True, sorry for the mistake. In OOP such mechanism is called a messaging system (with cache) I shouldn't have linked a reference to Send$$anonymous$$essage method which is not how Unity works internally.

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

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

Multiple Cars not working 1 Answer

Question about C# and using Methods... 2 Answers

Get the Caller of a static function? 1 Answer

C# Creating my own custom Unity Messages 2 Answers

Socket programming in unity 3 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