Triggers vs Collisions
Unity physics gives you two ways for two objects to meet, and every interactive thing you build this year is one or the other. Pick wrong and your coin pushes the player around the screen; pick right and the whole game feels invisible — which is the point. This is the complete reference for the physics family: pickups, hazards, hitboxes, ladders.
The one-line rule
A trigger asks "did we overlap?" A collider asks "can we occupy the same space?" — triggers are for events (you entered a region); collisions are for physics (you cannot walk through a wall). Everything else follows from that.
| Trigger | Collider (non-trigger) | |
|---|---|---|
| Is Trigger checked? | Yes | No |
| Does physics resolve the overlap? | No — objects pass through | Yes — objects push/stop |
| Message you receive | OnTriggerEnter2D / Stay2D / Exit2D | OnCollisionEnter2D / Stay2D / Exit2D |
| Handler argument | Collider2D (no contact points) | Collision2D (with contact points) |
| Needs a Rigidbody? | At least one object in the pair | At least one object in the pair |
| Your game uses it for | coins, potions, ladders, hitboxes, prompts | ground, walls, spikes, enemy contact |
Enter, Stay, Exit — the three moments
Every overlap has a lifecycle, and Unity calls one method per moment:
- Enter fires ONCE, the first frame the shapes overlap
- Stay fires EVERY frame the overlap continues
- Exit fires ONCE, the first frame they no longer overlap
The classic bug pair: Enter-only handlers mean "one event per bump" (a coin is collected once — but standing inside a hazard deals damage only once). Stay handlers mean "an event every frame" (a continuous hazard — but a coin collected in Stay would try to collect itself 60 times a second and crash on the second, because Destroy already removed it).
You will meet a hazard that genuinely needs both in 4.4, when the enemy attacks you. Damage on contact handles the first bump; damage while you remain in contact is what stops you simply standing inside an enemy forever. The moment you use Stay, you owe it a cooldown — because Stay fires every frame, and without a cooldown it drains your whole health bar in about a twentieth of a second.
The tag check — the first branch of every handler
A handler fires for EVERY overlapping object — walls, other enemies, the player, your own projectiles. The first line of almost every handler you write this year filters with CompareTag:
Every handler you write this year has the same three-part shape: filter (which object did we touch?), guard (is everything I need actually there?), then act and clean up (change the number, remove the pickup). You will write that shape four times before the year is out — coin, potion, axe, and damage — and the only parts that change are the tag you filter on and the number you change.
The silent-failure trap: a misspelled tag does not throw. The branch simply never matches and nothing happens, with no error to follow. When a trigger "does nothing," check the tag's spelling FIRST — in both places: the object's Tag field, and the string in your code.
Why pickups are triggers and hazards are colliders
A coin must not shove the player when collected — overlap is an event, not a wall: trigger. A spike is a physical thing you are stopped by or standing on, AND an event when touched — collider, with the damage handler riding on the collision message. The turret's projectile splits the difference, and you will decide this yourself in 3.4: its collider is usually a trigger (a bullet passes through the player's body until it chooses to "hit"), but it dies on contact with whatever you decide should stop it. Note that a bullet also needs a Rigidbody2D before any of this fires — one of the two objects in the pair must have a body, exactly as with the coin.
The settings that break everything
- Is Trigger unchecked when you meant it checked: your pickup becomes a wall. Symptom: the player stops short of the coin instead of collecting it.
- Rigidbody-less pairs: two static colliders never generate trigger or collision messages — at least one object in any pair needs a Rigidbody2D (the player carries one; enemies too). For a collision message it has to be a Dynamic body: a Kinematic body produces no collision messages against static colliders, so it passes through a wall in silence. Triggers are the exception — a Kinematic body still fires those.
- Layer collisions off: the Physics 2D matrix (Project Settings) can disable interactions between whole LAYERS — if your layer pair is off there, no message ever fires, tags or not. This is the same layer machinery as the ground-check raycast mask (6.2).
- Z position / sorting: sorting layers decide what DRAWS in front; physics happens regardless. An object drawn behind a wall still collides with it — visual depth and physical space are separate systems (7.2).