Are parameters in Unity event callbacks optional?

Hi!

I just answered another topic and after posting it I reviewed it one more time to see it all fit together. I realized that I had omitted the parameter in OnTriggerExit, but the code still ran. I got the callback even though it doesn't conform to the signature of the callback.


It seems that:

void OnTriggerExit ( )
{
}

Is just as good as:

void OnTriggerExit ( Collider other )
{
}

Except that the former omits information and possibly make cleaner code, if the parameter isn't important. The latter is the definition found in the scripting reference documents.


So this is news for me. Are parameters optional in unity callbacks or is this a fault in Unity? Is there any danger omitting parameters? If there are I can see this a potential cause of bugs in scripts.

I've heard it's better to omit the parameter if you're not using it because there's less overhead, however in practice there doesn't actually seem to be any difference, so possibly that's been optimized in the meantime. It doesn't hurt anything to leave it out, in any case.

they are not optional, the event callbacks are not optional too. see you can have or don't have any event you want so they are not abstract methods that you override or something like that. unity uses reflection to access those methods. so in collision it will check all of your scripts to see weather you have any method called OnTriggerEnter, if yes then it checks if you want an argument or not, if yes it will fill it for you and if no, it will not fill your parameter and just call the function. so it's faster to don't have the parameter if you don't want it. you can omit any parameter of any message in unity. (i mean messages like OnTriggerEnter and not those normal methods that you call with SendMessage).