Detect when this GameObject's collider overlaps with another trigger

Hello!

In my Unity project, I have an Entity GameObject and a Water GameObject. The Entity has a trigger (Circle), and a collider (Capsule2D). I also have a Water GameObject (CompositeCollider, Trigger). I want to detect when the Entity’s collider overlaps with the water’s trigger.

The problem is that OnCollision[Enter/Stay/Exit]2D doesn’t detect when the Collision overlaps a trigger. Using OnTrigger…2D then causes the Entity’s trigger (which is much larger than the collider) to count, so it acts submerged even when it isn’t.

If anyone could help me with this collider/trigger issue, it would be much appreciated.

Thanks in advance, bxzr

Confused a little by your question. It sounds like you’re expecting something that isn’t a collision (trigger) to produce an OnCollisionXXX which it will never do, it’s not a collision. The water trigger will only ever produce OnTriggerXXX callbacks which should make sense.

Getting the callback, even for things you’re not interested in shouldn’t be a problem, you can put logic in there to control what you’re interested in by using tags, components or other logic. By far the best way is to use layers so you only get callbacks between what you’re interested in so there’s no need to check using other means.

If using layers isn’t something you can do because there’s only 32 then you could use tags to indicate this and place the “Entity” collider/trigger on their own child gameobjects and tag them appropriately.

Note that using layers, you can also control this per-collider too using the Layer Overrides (Exclude Layers) i.e. set the “Entity Trigger” Collider to never contact the “Water” layer.

Here’s the API but you can also do this directly in the inspector: