- Home /
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?
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?
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.
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/
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.
Your answer
Follow this Question
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