Note: This documentation is about writing C# scripts using the Unity.U2D.Physics API. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to 2D physics instead.
In Unity, a collision happens when two objects occupy the same physical space.
To detect collision between Physics Core 2D API objects, Unity uses the PhysicsShape objects attached to the PhysicsBody. The shape defines the physics body for the purposes of physical collisions. The shape is similar to the Collider 2D component in the regular 2D physics system.
Shapes don’t need to be the same shape as the body, and you can add multiple shapes to one body.
For more information about adding a shape, refer to Create a physics object.
In the Physics Core 2D API, collisions are enabled by default.
How a shape reacts to collisions depends on its type:
For more information, refer to Configure collisions between Physics Core 2D API objects.
To detect collisions and overlaps using callbacks or events, refer to Detect collisions between objects.
Unity uses layers to determine which objects collide with each other.
By default the following applies:
To change this behavior, change the layers that objects are on, and the layers they collide with. For more information, refer to Configure collisions between 2D physics objects.
In the Physics Core 2D API, you can use a different set of 64 layers, instead of the standard set of 32 GameObject layers. For more information, refer to Use up to 64 layers.