unity-physicscore2d-performance

Optimizes and benchmarks Unity PhysicsCore2D simulations for large-scale body, shape, and joint workloads.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Physics simulations in Unity's PhysicsCore2D API can degrade quickly as body counts, joint networks, and collision pairs grow, causing long physics steps, memory spikes, and frame drops. This Skill provides expert guidance on capacity planning, benchmarking, and optimization so simulations stay within performance budgets.

Core Features & Use Cases

  • Capacity Planning & Benchmarking: Measure body, shape, contact, and joint limits using world.profile.simulationStep and world.counters, with stress-test examples like CapacityTest and JointGrid.
  • Optimization Techniques: Apply broad-phase tuning, shape simplification, sleep optimization, layer-based collision filtering, query batching, and joint reduction.
  • Large-Scale Simulation Patterns: Implement world partitioning, LOD, streaming, culling, object pooling, and batch operations with NativeArray/NativeList to avoid GC pressure.
  • Use Case: A developer building a mobile game with hundreds of dynamic debris bodies uses the CapacityTest pattern to find the maximum sustainable body count on target hardware, then applies layer filtering and sleeping to keep physics step time under 5ms.

Quick Start

Ask the assistant to help you benchmark and optimize your PhysicsCore2D scene, for example by reducing physics step time for a scene with thousands of dynamic bodies and joints.

Frequently Asked Questions about unity-physicscore2d-performance

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

FAQPage Schema
How do I benchmark PhysicsCore2D body capacity in Unity?

Spawn batches of dynamic bodies each frame while monitoring world.profile.simulationStep, and stop when the step time exceeds your target millisecond budget for a sustained number of frames. Read final body, shape, and contact counts from world.counters to determine capacity.

How many dynamic bodies can PhysicsCore2D handle?

Typical targets are 1000-5000 dynamic bodies on desktop and 500-1000 on mobile, depending on collision pair counts and shape complexity. Static bodies are virtually unlimited, while kinematic bodies cost between static and dynamic.

How do I optimize compound bodies with many shapes in PhysicsCore2D?

Set startMassUpdate to false in the PhysicsShapeDefinition when adding many shapes to one body, then call body.ApplyMassFromShapes() once at the end. This avoids recalculating mass after every individual shape creation.

Why is my PhysicsCore2D simulation step time so high?

Long physics steps usually come from too many active bodies, complex joint networks, high solver iteration counts, or many compound shapes. Reduce collision pairs with layer filtering, simplify geometry, enable sleeping, and lower solver iterations.

How do I reduce memory allocations in PhysicsCore2D?

Use NativeArray and NativeList with appropriate allocators instead of List<T>, preallocate object pools, and reuse query result containers. Batch body creation and destruction, and always dispose native collections to avoid leaks.

Does PhysicsCore2D performance guidance differ for mobile platforms?

Yes, mobile targets should use lower body counts around 500-1000, simpler collision geometry, aggressive culling, and lower solver iterations. WebGL has similar constraints plus WASM performance and browser memory limits.