OnTriggerEnter Being Called On Unexpected Object

Maybe I have a misunderstanding as to how OnTriggerEnter is supposed to work but here is my following situation and how it differs from what I would expect.


I have three objects in my scene - a player, an enemy, and an attack. The enemy and player both have rigid bodies and box colliders, neither of which is a trigger. The attack object has a box collider that IS a trigger. For scripts, the player has a script with nothing in it other than an OnTriggerEnter function that logs info to the console. The enemy has a simple script that just enables and disables the attack object in a cyclic pattern. When the attack is enabled it collides with the player.


Github with cloneable project/code: GitHub - valevalorin/TriggerTest


What I would expect to happen: The attack object is enabled and collides with the player. No console output is logged. The player object does not have a trigger collider on it so it’s OnTriggerEnter should never be called.


What actually happens: When the attack object collides with the player, the player’s OnTriggerEnter function gets called and output is logged to the console.


As far as I can tell, OnTriggerEnter should only be called on objects that actually have a trigger associated to them. Is this not how OnTriggerEnter works?

Hi,

OnTriggerEnter and other collision events are called on both colliding objects. So, in this case, it is called on attack object and on player.

This is explained here: Unity - Scripting API: Collider.OnTriggerEnter(Collider)