Loading lessons...
Physics Core 2D API
Physics Core 2D API
For high-performance games (like massive bullet-hell shooters or simulation engines), Unity provides a low-level, multithreaded 2D physics subsystem called Physics Core 2D.
What is the Physics Core 2D API?
Unlike standard Unity physics (which uses Rigidbody 2D and Collider 2D components inside GameObjects), the Physics Core 2D API:
- Interacts directly with the underlying Box2D simulation database using lightweight C# structs instead of heavy class components.
- Is designed to run with the C# Job System and Burst Compiler, letting you update thousands of bodies on background threads.
Shape & Body Definitions
Instead of dragging components in the Inspector, you create and allocate bodies programmatically:
- World: A custom 2D simulation area containing gravity configurations and bodies.
- Body Definitions (
BodyDef): Structs that store mass, velocity, inertia, and position. - Shape Definitions (
ShapeDef): Structs that define geometric outlines (box, circle, polygon).
Memory Management & Destroying Objects
Since Physics Core 2D uses low-level native allocations, you must manually manage the memory life-cycle:
- Free all allocated worlds and shapes using their respective
Destroy()methods. - Failing to destroy worlds when unloading a scene causes native memory leaks that are hard to debug.
TL;DR
- Physics Core 2D is a low-level, high-performance C# physics API.
- Works with the C# Job System for multithreaded, component-free simulations.
- Uses
BodyDefandShapeDefstructs instead of GameObject components. - Requires manual memory management and destruction of custom worlds.