t1k:unity:dots-combat:physics
| Field | Value |
|---|---|
| Module | dots-combat |
| Version | 2.3.8 |
| Effort | high |
| Tools | — |
Keywords: collision, DOTS, physics, rigidbody
How to invoke
Section titled “How to invoke”/t1k:unity:dots-combat:physicsUnity DOTS Physics
Section titled “Unity DOTS Physics”Skill Purpose
Section titled “Skill Purpose”This skill provides a complete reference for Unity Physics 1.4.5 in ECS/DOTS. To implement any physics feature, consult the relevant reference file listed below before writing code.
Prerequisite:
dots-ecsskill (ISystem, Baker, SystemAPI, ECB patterns).
When This Skill Triggers
Section titled “When This Skill Triggers”- “add physics to entity”, “rigid body”, “PhysicsCollider”, “PhysicsVelocity”
- “raycast”, “spherecast”, “collider cast”, “distance query”, “overlap”
- “collision event”, “trigger event”, “OnCollision”, “OnTrigger”
- “physics joint”, “hinge”, “ball socket”, “prismatic”, “motor”
- “PhysicsShape”, “PhysicsBody”, “bake physics”, “physics authoring”
- “FixedStepSimulationSystemGroup”, “PhysicsSimulationGroup”
Quick Reference
Section titled “Quick Reference”| Topic | Reference File |
|---|---|
| Components, collider factory, entity creation, collision filters, compound colliders | components-setup-guide.md |
| Raycasting, sphere/box casts, point distance, overlap, batched queries | queries-raycasting-guide.md |
| Collision events, trigger events, stateful enter/stay/exit events | events-guide.md |
| Joints, motors, forces, impulses, PhysicsCustomTags | joints-forces-guide.md |
| Baking, custom bakers, PhysicsStep config, system ordering | authoring-config-guide.md |
| Advanced queries — custom collectors, compound collider casts, query optimization | queries-advanced-guide.md |
Terminology
Section titled “Terminology”- DOTS — Data-Oriented Technology Stack
- ECS — Entity Component System
- ECB — EntityCommandBuffer
Key Conventions
Section titled “Key Conventions”- Namespace:
DOTSAI.Physics - Static body:
LocalTransform+LocalToWorld+PhysicsCollider+PhysicsWorldIndex - Dynamic body: add
PhysicsVelocity+PhysicsMass+PhysicsDamping+PhysicsGravityFactor - To query physics world, use
SystemAPI.GetSingleton<PhysicsWorldSingleton>()inOnUpdateonly - To receive collision events, set collider Collision Response = Raise Collision Events
- To receive trigger events, set collider Collision Response = Raise Trigger Events
- To modify a shared collider blob at runtime, call
MakeUniquebefore writing - System ordering: run before
PhysicsSystemGroupto read broadphase; afterPhysicsSimulationGroupto handle events PhysicsVelocity.Angularis in local body space- At least one body in a joint pair must have
PhysicsVelocity - Do not add
PhysicsVelocityto static bodies
Performance Rules
Section titled “Performance Rules”- Always Burst-compile physics systems —
[BurstCompile]on struct and methods - Use
CollisionWorld.CastRay(DOTS Physics) — neverUnityEngine.Physics.Raycast(managed, can’t see SubScene-baked colliders) - Batch queries when possible — use
NativeArray<RaycastInput>withCollisionWorld.CastRayoverloads for multiple rays - Use
CollisionFilterto narrow ray/overlap scope — reduces broadphase checks - Cache
PhysicsWorldSingletonat the start ofOnUpdate— avoid multipleGetSingletoncalls - System ordering matters — read physics state BEFORE
PhysicsSystemGroup; handle events AFTERPhysicsSimulationGroup - Use
[ReadOnly] CollisionWorldin parallel jobs — physics world is read-only after step - Avoid
MakeUniquein hot paths — it copies the entire blob. Do it once during setup, not every frame
Common Gotchas
Section titled “Common Gotchas”| Issue | Fix |
|---|---|
| Events not firing | Collider Collision Response must be set to raise events |
GetSingleton fails | Call in OnUpdate, not OnCreate |
| Collider changes lost | Call MakeUnique before modifying shared blob |
| Joint has no effect | At least one body must have PhysicsVelocity |
| Static body moves | Remove PhysicsVelocity from static bodies |
| Stale query data | Use [UpdateBefore(typeof(PhysicsSystemGroup))] |
Custom PhysicsBodyAuthoring missing | Import “Custom Physics Authoring” sample from Package Manager |
| Classic raycasts miss SubScene entities | Use DOTS CollisionWorld.CastRay, not UnityEngine.Physics.Raycast |
Simulation Pipeline (from Unity Physics docs)
Section titled “Simulation Pipeline (from Unity Physics docs)”1. Physics World Building → CollisionWorld + DynamicsWorld from entity components2. Broadphase Detection → bounding volume pair identification3. Narrowphase Detection → actual contacts and penetration depth4. Constraint Solver → collision response + joint constraints → velocity updates5. Integration → advance bodies by timestep6. Export → write positions/orientations to entitiesCollisionFilter Quick Reference
Section titled “CollisionFilter Quick Reference”// Two colliders interact when: (A.BelongsTo & B.CollidesWith) != 0 AND (B.BelongsTo & A.CollidesWith) != 0new CollisionFilter{ BelongsTo = 1u << layerIndex, // which layer(s) this collider is on CollidesWith = 1u << otherLayer, // which layer(s) to interact with GroupIndex = 0 // positive = force collide, negative = force ignore (same pair)}Documentation
Section titled “Documentation”- Unity Physics Manual
- Unity Physics API
- Physics 1.4.5 Changelog
- Context7 library:
/websites/unity3d_packages_com_unity_physics_1_4(833 snippets, High reputation)