unity-physicscore2d

Guides onboarding and API usage for Unity 6000.5 PhysicsCore2D in the Unity.U2D.Physics namespace.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Unity's new PhysicsCore2D API (Unity.U2D.Physics) is recent, often post-dates AI training data, and is easily confused with the legacy component-based Physics2D system, leading to invented or obsolete API calls. This Skill orients you to the correct namespace, concurrency model, and object lifecycle, and routes you to the right topic or API sub-skill.

Core Features & Use Cases

  • API Verification Protocol: Enforces a strict never-guess rule for PhysicsCore2D and adjacent APIs (Unity.Collections, Unity.Mathematics, Unity.Jobs), with a documented verification order using sub-skills and official docs.
  • Core Concepts Explained: Covers the WORM lock concurrency model, definition structs, handle-struct semantics, transformObject synchronization, batch creation, and the OnEnable/OnDisable lifecycle pattern.
  • Sub-Skill Routing: Directs you to the correct topic skill (joints, bodies, queries, batching, factories) or *-api skill for specific type references.
  • Use Case: You are writing a MonoBehaviour that creates dynamic physics bodies in Unity 6000.5. The Skill ensures you use PhysicsWorld.defaultWorld, PhysicsBodyDefinition.defaultDefinition, batch creation with Allocator.Persistent, and proper destruction in OnDisable.

Quick Start

Ask the assistant to explain how PhysicsCore2D differs from the old Physics2D and to show the correct way to create and destroy a PhysicsBody in Unity 6000.5.

Frequently Asked Questions about unity-physicscore2d

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

FAQPage Schema
How do I create a PhysicsBody in Unity PhysicsCore2D?

Get the default world with PhysicsWorld.defaultWorld, configure a PhysicsBodyDefinition starting from PhysicsBodyDefinition.defaultDefinition, then call world.CreateBody(definition) in OnEnable. Destroy it in OnDisable after checking body.isValid.

What is the difference between PhysicsCore2D and the old Physics2D?

PhysicsCore2D (Unity.U2D.Physics) is a new low-level, non-component API that is fully thread-safe and job-compatible. The old Physics2D uses GameObject components like Rigidbody2D and Collider2D, is incompatible with the new API, and is in maintenance mode only.

Is Unity PhysicsCore2D thread-safe for use in jobs?

Yes, PhysicsCore2D is 100% thread-safe and callable from Burst-compiled jobs. It uses a per-world WORM lock: reads run concurrently, while writes like CreateBody are serialized, so batch creation via PhysicsBody.CreateBatch is preferred over parallel creation loops.

How do I sync a PhysicsBody with a GameObject Transform?

Set the PhysicsBody.transformObject property to the GameObject's Transform after creating the body. The Transform's position and rotation then update automatically during simulation, with no manual synchronization code needed.

Why can't I set a property on a PhysicsBody from a NativeArray index?

C# forbids setting properties on by-value struct indexer results. Copy the handle into a local variable, set the property there, and no writeback is needed because PhysicsBody is a handle struct referencing the underlying object.

When should I use Allocator.Persistent with PhysicsCore2D NativeArrays?

Use Allocator.Persistent whenever a NativeArray returned by PhysicsCore2D is stored as a field persisting across frames, such as batch-created bodies. The default Allocator.Temp only lasts one frame and causes errors if accessed later.