How do built-in auto called function actually work ?

Hello everyone !

I have a question concerning functions that are called automatically when some events occur. Functions like OnMouseEnter(), OnMouseExit(), etc. I am wondering what happens behind these. Are they kind of checked up in an hidden Update function at each frame ?

For instance, is there any gain of performance using OnMouseOver() rather than coding it yourself like following :

// I assume IsMouseOver() is a custom function that returns true whenever the mouse is hovering the object this script is attached to.
private void Update()
{
   if (isMouseOver())
   {
      Debug.Log("Hovering");
      // Do whatever you want here
   {
}

Regards

Every frame, Unity follows an event queue, The update is one event, and handling events is another event, you can read more here:

Unless you are a senior experienced programmer, most likely all functions done by unity itself have a better performance.