unity-physicscore2d-composer

Compose complex 2D collision shapes in Unity PhysicsCore2D using boolean geometry operations.

735|105|Updated Mar 4, 2017
One-click install
npx skills add https://github.com/Unity-Technologies/PhysicsExamples2D --skill unity-physicscore2d-composer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-physicscore2d-composer
Source: https://github.com/Unity-Technologies/PhysicsExamples2D/tree/main/.claude/skills/unity-physicscore2d-composer
Command: npx skills add https://github.com/Unity-Technologies/PhysicsExamples2D --skill unity-physicscore2d-composer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building complex 2D collision shapes from simple primitives in Unity's PhysicsCore2D API requires correct use of PhysicsComposer boolean operations, allocator management, and shape attachment, where mistakes cause leaked native memory, discarded geometry, or wrong output shapes.

Core Features & Use Cases

  • Boolean Geometry Composition: Combine CircleGeometry, CapsuleGeometry, PolygonGeometry, and raw vertex spans using OR, AND, NOT, and XOR operations with explicit layer ordering.
  • Polygon and Chain Output: Generate filled convex polygon decompositions via CreatePolygonGeometry or hollow edge-only collision via CreateChainGeometry, then attach results with CreateShapeBatch or CreateChain.
  • Job-Safe Workflows: Use PhysicsComposer inside Burst-compiled jobs with Allocator.TempJob while respecting main-thread body creation constraints.
  • Use Case: Create a donut-shaped collider by adding a large outer circle as the base layer, subtracting a smaller inner circle with NOT, generating the polygon geometry, and attaching it to a dynamic body with CreateShapeBatch.

Quick Start

Ask the AI to create a Unity PhysicsCore2D script that combines a box and two circles with PhysicsComposer boolean operations and attaches the resulting polygons to a physics body.

Frequently Asked Questions about unity-physicscore2d-composer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I combine multiple shapes with PhysicsComposer in Unity PhysicsCore2D?

Create a composer with PhysicsComposer.Create(), add geometry layers with AddLayer specifying an operation like OR, AND, or NOT, then call CreatePolygonGeometry to get a NativeArray of PolygonGeometry. Attach the results to a body with CreateShapeBatch and dispose all native arrays.

How do I cut a hole in a 2D collision shape in Unity?

Add the outer shape as the base layer, then add the inner shape with PhysicsComposer.Operation.NOT to subtract it. The composer decomposes the concave result into multiple convex polygons automatically.

Why does CreatePolygonGeometry return zero polygons?

This happens when boolean operations produce no geometry, such as an AND between non-overlapping shapes or a full subtraction. Always check polygons.Length before creating shapes, and inspect composer.rejectedGeometryCount for discarded thin or collinear polygons.

Can PhysicsComposer be used inside Unity Burst jobs?

Yes, PhysicsComposer is thread-safe and works in Burst-compiled jobs. Use Allocator.TempJob for the composer and output arrays since Allocator.Temp is forbidden in jobs, and create bodies and shapes only on the main thread.

When should I use CapsuleGeometry instead of PhysicsComposer?

Use CapsuleGeometry.Create directly when you only need a single capsule shape, since it avoids composer overhead. Reserve PhysicsComposer for cases requiring boolean operations across multiple geometry layers.