Hi, I’m very new to the unity engine and I’d like to ask the community a simple question that bugs me a bit. I’ve studied c# with console programs and then moved to forms, and i’m generally used to create the “engine” of my applications, this is why I find it hard to understand for example how this method works.
What is exactly that calls this method and why? A particular delegate/event ? Is there some documentation that explain exactly how those kinds of methods works/gets called by the unity engine ?
Most important : If that is an inherited method from monobehaviour, why we’re not supposed to override it ?
It’s a method that is called when a collider with the “trigger” tag set collides with the collider attached to the same object as the script (assuming at least one of the colliding objects has a Rigidbody2D attached). It is only called once, when the colliders touch for the first time, and will not be called again between those two colliders until they separate. The purpose of this is if you want a one-time action to occur when the colliders first touch.
The reason you don’t have to override it is because MonoBehaviour is not really a C# class. It’s actually a C# hook into C++, and it’s the C++ code that eventually calls the method. Unity’s base engine is written in C++ (for speed), and the scripts you write are attached onto that engine, meaning that some of the language constraints you find in C# aren’t retained between the language. It’s a little messy, like a lot of Unity, and could be done in a neater and more consistent way, but that’s the explanation, since you asked for it.