### Custom Physics System Group Example Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/manual/group-body.html Define a custom physics system group to simulate entities in a specific world index. This example creates a group for world index 1 and shares static entities with the main world. ```csharp [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] public partial class UserPhysicsGroup : CustomPhysicsSystemGroup { public UserPhysicsGroup() : base(1, true) {} // our physics group will simulate entities with world index 1, and share static entities with main world } [UpdateInGroup(PhysicsInitializeGroup)] // As the system updates inside [PhysicsSinitializeGroup], it will automatically be ran inside UserPhysicsGroup as well public partial class CheckWorldIndexSystem : SystemBase { protected override void OnUpdate() { var physicsWorldSingleton = GetSingleton(); if (physicsWorldSingleton.PhysicsWorldIndex.Value == 0) { // ... // When ran as part of main physics group, this code path will be hit. } else { // ... // When ran as part of UserPhysicsGroup, this code path will be hit. } } } ``` -------------------------------- ### ColliderCastInput Constructor (Collider, Start, End, Orientation, QueryColliderScale) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ColliderCastInput.html Initializes a ColliderCastInput with a collider, start, end points, orientation, and an optional query collider scale. This constructor allows specifying the collider's orientation and scale for the cast. ```csharp public ColliderCastInput(BlobAssetReference collider, float3 start, float3 end, quaternion orientation, float queryColliderScale = 1) ``` -------------------------------- ### ColliderCastInput Constructor (Collider, Start, End) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ColliderCastInput.html Initializes a ColliderCastInput with a collider, start, and end points. Use this constructor when the collider's orientation is the default (identity quaternion). ```csharp public ColliderCastInput(BlobAssetReference collider, float3 start, float3 end) ``` -------------------------------- ### PhysicsWorldBuilder Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.html Provides utility methods for the construction and setup of physics worlds. ```APIDOC ## PhysicsWorldBuilder ### Description Utilities for building a physics world. ``` -------------------------------- ### Creating Physics Body from Scratch Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/manual/create-body.html This method demonstrates how to create a physics body dynamically from scratch, including setting up rendering components and collider information. ```csharp using UnityEngine; using Unity.Entities; using Unity.Mathematics; using Unity.Physics; using Unity.Rendering; using Unity.Transforms; using Collider = Unity.Physics.Collider; using Unity.Collections.LowLevel.Unsafe; public partial class SphereSpawningSystem : SystemBase { protected override void OnUpdate() { var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); var renderer = sphere.GetComponent(); var mesh = sphere.GetComponent().mesh; var renderMeshDescription = new RenderMeshDescription(renderer); var renderMeshArray = new RenderMeshArray(new[] { renderer.material }, new[] { mesh }); var materialMeshInfo = MaterialMeshInfo.FromRenderMeshArrayIndices(0, 0); Object.DestroyImmediate(sphere); var entity = CreateDynamicSphere(EntityManager, renderMeshArray, materialMeshInfo, renderMeshDescription, 1, 0.5f, new float3(0, 5, 0), quaternion.identity); EntityManager.SetName(entity, "Sphere"); Enabled = false; } } ``` -------------------------------- ### CapsuleGeometry Vertex0 Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CapsuleGeometry.html Sets or gets the starting position of the capsule's inner line segment. ```csharp public float3 Vertex0 { get; set; } ``` -------------------------------- ### Get Collider Restitution Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Collider.html Retrieves the restitution value of a collider. For compound colliders, you can specify a ColliderKey to get the restitution of a specific child. ```csharp public float GetRestitution() { // Implementation details } ``` ```csharp public float GetRestitution(ColliderKey colliderKey) { // Implementation details } ``` -------------------------------- ### Build Physics World Immediately (with Entity Queries) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldBuilder.html Fills the PhysicsWorld with bodies and joints using specified entity queries and builds its broadphase BVH immediately. This is suitable for direct, synchronous world construction. ```csharp public static void BuildPhysicsWorldImmediate(ref PhysicsWorld world, NativeReference haveStaticBodiesChanged, in PhysicsWorldData.PhysicsWorldComponentHandles componentHandles, float timeStep, float3 gravity, uint lastSystemVersion, EntityQuery dynamicEntityGroup, EntityQuery staticEntityGroup, EntityQuery jointEntityGroup) ``` -------------------------------- ### Accessing PhysicsWorldSingleton in SystemBase Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/manual/physics-singletons.html Illustrates how to obtain the PhysicsWorldSingleton within a SystemBase class for performing raycasts. Shows scheduling a job and direct main thread access, including dependency management. ```csharp // SystemBase version [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateBefore(typeof(PhysicsSystemGroup))] // Make sure that the running order of systems is correct public partial class CastRaySystemBaseExample : SystemBase { public partial struct CastRayJob : IJob { public PhysicsWorldSingleton World; [BurstCompile] public void Execute() { World.CastRay(...); } } protected override void OnUpdate() { PhysicsWorldSingleton physicsWorldSingleton = GetSingleton(); // Version that schedules a job state.Dependency = new CastRayJob { World = physicsWorldSingleton }.Schedule(state.Dependency); // Main thread version - be sure to complete the dependency CompleteDependency(); physicsWorldSingleton.CastRay(...); // It is also possible to access the PhysicsWorld PhysicsWorld world = physicsWorldSingleton.PhysicsWorld; } } ``` -------------------------------- ### ColliderAspect.Type Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets the type of the collider. ```APIDOC ## Type { get; } ### Description Gets the collider type. ### Property Value - **ColliderType** - The colldier type. ``` -------------------------------- ### ColliderAspect.CollisionType Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets the collision type of the collider. ```APIDOC ## CollisionType { get; } ### Description Gets the collision type. ### Property Value - **CollisionType** - The collision type. ``` -------------------------------- ### Step Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Simulation.html Steps the world immediately, advancing the physics simulation to the next state. ```APIDOC ## Step(SimulationStepInput) ### Description Steps the world immediately. ### Parameters - **input** (SimulationStepInput) - The input. ### Returns void ``` -------------------------------- ### Build Physics World Immediately (with PhysicsWorldData) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldBuilder.html Fills the PhysicsWorld with bodies and joints and builds its broadphase BVH immediately on the current thread. This overload requires a SystemState for updating type handles. ```csharp public static void BuildPhysicsWorldImmediate(ref SystemState systemState, ref PhysicsWorldData physicsData, float timeStep, float3 gravity, uint lastSystemVersion) ``` -------------------------------- ### ColliderAspect.Collider Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets or sets the BlobAssetReference for the collider. ```APIDOC ## Collider { get; set; } ### Description Gets or sets the collider. ### Property Value - **BlobAssetReference** - The collider. ``` -------------------------------- ### ColliderAspect.Entity Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets the entity associated with this ColliderAspect. ```APIDOC ## Entity ### Description The entity of this aspect. ### Field Value - **Entity** (Entity) - ``` -------------------------------- ### Schedule Physics World Build with Full Parameters Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldBuilder.html Schedules jobs to fill the PhysicsWorld with bodies and joints and build the broadphase BVH. Requires a SystemState to update component handles. This overload accepts detailed parameters for gravity, time step, and threading options. ```csharp public static JobHandle SchedulePhysicsWorldBuild(ref SystemState systemState, ref PhysicsWorld world, ref NativeReference haveStaticBodiesChanged, in PhysicsWorldData.PhysicsWorldComponentHandles componentHandles, in JobHandle inputDep, float timeStep, bool isBroadphaseBuildMultiThreaded, float3 gravity, uint lastSystemVersion, EntityQuery dynamicEntityQuery, EntityQuery staticEntityQuery, EntityQuery jointEntityQuery) ``` -------------------------------- ### SimulationSingleton InitializeFromSimulation Method Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.SimulationSingleton.html Initializes the SimulationSingleton from a given Simulation object. This method allows updating the singleton's state based on an existing simulation. ```csharp public void InitializeFromSimulation(ref Simulation simulation) ``` -------------------------------- ### Initialize Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.BoxCollider.html Initializes the box collider, enabling it to be created on the stack. ```APIDOC ## Initialize(BoxGeometry, CollisionFilter, Material) ### Description Initializes the box collider, enabling it to be created on the stack. ### Method public void Initialize(BoxGeometry geometry, CollisionFilter filter, Material material) ### Parameters #### Path Parameters - **geometry** (BoxGeometry) - The geometry. - **filter** (CollisionFilter) - Specifies the filter. - **material** (Material) - The material. ``` -------------------------------- ### EarlyJobInit() Method Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.IJacobiansJobExtensions.html Initializes jobs that implement IJacobiansJobBase. Use this method to prepare jobs before scheduling them. ```csharp public static void EarlyJobInit() where T : struct, IJacobiansJobBase ``` -------------------------------- ### ColliderAspect.Scale Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets or sets the uniform scale of the collider. ```APIDOC ## Scale { get; set; } ### Description Gets or sets the uniform scale. ### Property Value - **float** - The scale. ``` -------------------------------- ### ColliderKeyPath.Empty Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ColliderKeyPath.html Gets the default empty ColliderKeyPath. ```APIDOC ## Empty ### Description Gets the empty ColliderKeyPath. ### Property Value - **ColliderKeyPath** - The empty ColliderKeyPath. ``` -------------------------------- ### PhysicsWorldData Constructor Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldData.html Initializes PhysicsWorldData with the system state and a physics world index. Ensure this is called within the same system where PhysicsWorldData will be used. ```csharp public PhysicsWorldData(ref SystemState state, in PhysicsWorldIndex worldIndex) ``` -------------------------------- ### GetCollisionFilter Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.PolygonCollider.html Gets the collision filter associated with the polygon collider. ```APIDOC ## GetCollisionFilter ### Description Gets the collision filter associated with the polygon collider. ### Method Signature ```csharp public CollisionFilter GetCollisionFilter() ``` ### Returns - **CollisionFilter** - The collision filter. ``` -------------------------------- ### Schedule Physics World Build with Simplified Parameters Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldBuilder.html Schedules jobs to fill the PhysicsWorld with bodies and joints and build the broadphase BVH. This overload simplifies parameter passing by using a PhysicsWorldData object. ```csharp public static JobHandle SchedulePhysicsWorldBuild(ref SystemState systemState, ref PhysicsWorldData physicsData, in JobHandle inputDep, float timeStep, bool isBroadphaseBuildMultiThreaded, float3 gravity, uint lastSystemVersion) ``` -------------------------------- ### BeginColliderBakingSystem Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Authoring.BeginColliderBakingSystem.html This system is called before all other collider baking systems. Its purpose is to initialize the hash delegate and declare a new BlobAssetComputationContext. ```APIDOC ## Class BeginColliderBakingSystem Baking system for colliders: Stage 1. This system is called before all other collider baking systems. The purpose of this system is to initialize the hash delegate and the declare a new BlobAssetComputationContext. ##### Inheritance object ComponentSystemBase SystemBase BeginColliderBakingSystem ###### **Namespace** : Unity.Physics.Authoring ###### **Assembly** : Unity.Physics.Hybrid.dll ``` -------------------------------- ### PhysicsWorldIndex.Value Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.PhysicsWorldIndex.html Gets the index of the physics world that this entity belongs to. ```APIDOC ## PhysicsWorldIndex.Value ### Description Index of the physics world that this entity belongs to. ### Field Value - **uint** - The zero-based index of the physics world. ``` -------------------------------- ### CollisionWorld.NumBodies Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CollisionWorld.html Gets the total number of bodies in the collision world. ```APIDOC ## CollisionWorld.NumBodies ### Description Gets the number of bodies. ### Property Value - **int** - The total number of bodies. ``` -------------------------------- ### Step Simulation Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Simulation.html Steps the world immediately. This is a synchronous operation that advances the physics simulation. ```csharp public void Step(SimulationStepInput input) ``` -------------------------------- ### CollisionWorld.Bodies Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CollisionWorld.html Gets the NativeArray of all rigid bodies in the collision world. ```APIDOC ## CollisionWorld.Bodies ### Description Gets the bodies. ### Property Value - **NativeArray** - The bodies. ``` -------------------------------- ### Step Simulation Immediately Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Simulation.html Steps the simulation immediately on a single thread without spawning any jobs. This method requires a SimulationContext to manage the simulation state. ```csharp public static void StepImmediate(SimulationStepInput input, ref SimulationContext simulationContext) ``` -------------------------------- ### Initialize Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CylinderCollider.html Initializes the cylinder collider, enabling it to be created on the stack. ```APIDOC ## Initialize(CylinderGeometry, CollisionFilter, Material) ### Description Initializes the cylinder collider, enables it to be created on stack. ### Method ```csharp public void Initialize(CylinderGeometry geometry, CollisionFilter filter, Material material) ``` ### Parameters #### Path Parameters - **geometry** (CylinderGeometry) - The geometry. - **filter** (CollisionFilter) - Specifies the filter. - **material** (Material) - The material. ``` -------------------------------- ### GetCollisionFilter Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.BoxCollider.html Gets the collision filter associated with the box collider. ```APIDOC ## GetCollisionFilter ### Description Gets the collision filter associated with the box collider. ### Method public CollisionFilter GetCollisionFilter() ### Returns - **CollisionFilter** - The collision filter. ``` -------------------------------- ### ColliderAspect.WorldFromCollider Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets or sets the world transform of the collider aspect. ```APIDOC ## WorldFromCollider { get; set; } ### Description Gets or sets the world transform of a collider aspect. ### Property Value - **LocalTransform** - The world space transform. ``` -------------------------------- ### PhysicsStepAuthoring Class Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Authoring.PhysicsStepAuthoring.html Parameters describing how to step the physics simulation. If this component is not present, default values will be used. ```APIDOC ## Class PhysicsStepAuthoring Parameters describing how to step the physics simulation. If this component is not present, default values will be used. ##### Inheritance object Object Component Behaviour MonoBehaviour PhysicsStepAuthoring ``` -------------------------------- ### Accessing PhysicsWorldSingleton in ISystem Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/manual/physics-singletons.html Demonstrates how to get the PhysicsWorldSingleton within an ISystem and use it for raycasting, both in jobs and on the main thread. Ensures correct system ordering with UpdateInGroup and UpdateBefore attributes. ```csharp // ISystem version [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] [UpdateBefore(typeof(PhysicsSystemGroup))] // Make sure that the running order of systems is correct public partial struct CastRayISystemExample : ISystem { [BurstCompile] public partial struct CastRayJob : IJob { public PhysicsWorldSingleton World; public void Execute() { World.CastRay(...); } } [BurstCompile] public void OnUpdate(ref SystemState state) { PhysicsWorldSingleton physicsWorldSingleton = SystemAPI.GetSingleton(); // Version that schedules a job state.Dependency = new CastRayJob { World = physicsWorldSingleton }.Schedule(state.Dependency); // Main thread version - be sure to complete the dependency state.CompleteDependency(); physicsWorldSingleton.CastRay(...); // It is also possible to access the PhysicsWorld PhysicsWorld world = physicsWorldSingleton.PhysicsWorld; } } ``` -------------------------------- ### ColliderAspect.Rotation Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets or sets the world space rotation of the collider. ```APIDOC ## Rotation { get; set; } ### Description Gets or sets the world space rotation. ### Property Value - **quaternion** - The world space rotation. ``` -------------------------------- ### CompleteDependencyBeforeRW Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.RigidBodyAspect.html Completes the dependency chain for read and write access to rigid body components. ```APIDOC ## CompleteDependencyBeforeRW(ref SystemState) ### Description Completes the dependency chain required for this component to have read and write access. So it completes all write dependencies of the components, buffers, etc. to allow for reading, and it completes all read dependencies, so we can write to it. ### Method Signature ```csharp public void CompleteDependencyBeforeRW(ref SystemState state) ``` ### Parameters #### Parameters - **state** (SystemState) - Required - The SystemState containing an EntityManager storing all dependencies. ``` -------------------------------- ### ColliderAspect.Position Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Gets or sets the world space position of the collider. ```APIDOC ## Position { get; set; } ### Description Gets or sets the world space position. ### Property Value - **float3** - The world space position. ``` -------------------------------- ### ColliderKey.Value Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ColliderKey.html Gets the underlying uint value of the ColliderKey. ```APIDOC ## ColliderKey.Value ### Description Gets or sets the value. ### Property Value - **Value** (uint) - The value. ``` -------------------------------- ### SimulationStepInput Syntax Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.SimulationStepInput.html Defines the structure for simulation step inputs in Unity Physics. ```csharp public struct SimulationStepInput ``` -------------------------------- ### ColliderKeyPath.Key Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ColliderKeyPath.html Gets the collider key associated with this path. ```APIDOC ## Key ### Description Gets the collider key. ### Property Value - **ColliderKey** - The collider key. ``` -------------------------------- ### PhysicsBuildWorldGroup Class Overview Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsBuildWorldGroup.html Provides an overview of the PhysicsBuildWorldGroup class, its inheritance, and its role in the Unity Physics system. ```APIDOC ## Class PhysicsBuildWorldGroup Group responsible to build the physics world data and wait for any dependencies before the next simulation. ##### Inheritance object ComponentSystemBase SystemBase ComponentSystemGroup PhysicsBuildWorldGroup ###### **Namespace** : Unity.Physics.Systems ###### **Assembly** : Unity.Physics.dll ``` -------------------------------- ### ChildCollider Collider Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ChildCollider.html Gets the Collider associated with this ChildCollider. ```csharp public Collider* Collider { get; } ``` -------------------------------- ### Build Broadphase BVH Immediately Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldBuilder.html Builds the broadphase Bounding Volume Hierarchy (BVH) for the PhysicsWorld on the current thread. Use this when immediate execution is required and dependencies are managed manually. ```csharp public static void BuildBroadphaseBVHImmediate(ref PhysicsWorld world, bool haveStaticBodiesChanged, float timeStep, float3 gravity) ``` -------------------------------- ### ISimulation Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.html Interface for simulations. ```APIDOC interface ISimulation ``` -------------------------------- ### Length Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.BlobArray.Accessor-1.html Gets the total number of elements in the BlobArray. ```APIDOC ## Length ### Description Gets the length of the BlobArray. ### Property Value - **int** - The length. ``` -------------------------------- ### BlobArray.Accessor.Enumerator.Current Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.BlobArray.Accessor-1.Enumerator.html Gets the current element in the enumeration. ```APIDOC ## Current { get; } ### Description Gets the current. ### Property Value - **T** - The current. ``` -------------------------------- ### Solver.StabilizationData Constructor Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Solver.StabilizationData.html Initializes a new instance of the Solver.StabilizationData struct with the provided simulation step input and context. ```APIDOC ## StabilizationData(SimulationStepInput stepInput, SimulationContext context) ### Description Constructor. ### Parameters - **stepInput** (SimulationStepInput) - Required - The step input. - **context** (SimulationContext) - Required - The context. ``` -------------------------------- ### GetRequiredComponentTypeCount Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.RigidBodyAspect.html Gets the number of non-optional components associated with this aspect. ```APIDOC ## GetRequiredComponentTypeCount() ### Description Get the number of required (i.e. non-optional) components contained in this aspect. ### Method Signature ```csharp public static int GetRequiredComponentTypeCount() ``` ### Returns - **int** - The number of required (i.e. non-optional) components contained in this aspect. ``` -------------------------------- ### SchedulePhysicsWorldBuild (with detailed entity queries) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldBuilder.html Schedules jobs to fill the PhysicsWorld with bodies and joints, and builds the broadphase BVH. This overload allows for specific entity queries for dynamic, static, and joint entities. ```APIDOC ## SchedulePhysicsWorldBuild ### Description Schedules jobs to fill the PhysicsWorld with bodies and joints (using entities from physicsData's queries) and build broadphase BoundingVolumeHierarchy. Needs a SystemState to update component handles. ### Method Signature public static JobHandle SchedulePhysicsWorldBuild(ref SystemState systemState, ref PhysicsWorld world, ref NativeReference haveStaticBodiesChanged, in PhysicsWorldData.PhysicsWorldComponentHandles componentHandles, in JobHandle inputDep, float timeStep, bool isBroadphaseBuildMultiThreaded, float3 gravity, uint lastSystemVersion, EntityQuery dynamicEntityQuery, EntityQuery staticEntityQuery, EntityQuery jointEntityQuery) ### Parameters #### Path Parameters - **systemState** (SystemState) - [in,out] State of the system. - **world** (PhysicsWorld) - [in,out] The world. - **haveStaticBodiesChanged** (NativeReference) - [in,out] The have static bodies changed. - **componentHandles** (PhysicsWorldData.PhysicsWorldComponentHandles) - The component handles. - **inputDep** (JobHandle) - The input dependency. - **timeStep** (float) - The time step. - **isBroadphaseBuildMultiThreaded** (bool) - True if the broadphase build is multi threaded, false if not. - **gravity** (float3) - The gravity. - **lastSystemVersion** (uint) - The last system version. - **dynamicEntityQuery** (EntityQuery) - Group the dynamic entity belongs to. - **staticEntityQuery** (EntityQuery) - The static entity query. - **jointEntityQuery** (EntityQuery) - Group the joint entity belongs to. ### Returns - **JobHandle** - A JobHandle. ``` -------------------------------- ### Spawning Spheres from Prefab with ConfigAuthoring Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/manual/create-body.html Use ConfigAuthoring to spawn multiple instances of a prefab at runtime. This system runs once to set up initial entities. ```csharp using UnityEngine; using Unity.Entities; using Unity.Burst; using Unity.Mathematics; using Unity.Transforms; public struct Config : IComponentData { public Entity SpherePrefab; public int SphereCount; } public class ConfigAuthoring : MonoBehaviour { public GameObject SpherePrefab; public int SphereCount; } public class ConfigBaker : Baker { public override void Bake(ConfigAuthoring authoring) { AddComponent(new Config { SpherePrefab = GetEntity(authoring.SpherePrefab), SphereCount = authoring.SphereCount, }); } } public partial struct SphereSpawningSystem : ISystem { [BurstCompile] public void OnUpdate(ref SystemState state) { var config = SystemAPI.GetSingleton(); var ecbSingleton = SystemAPI.GetSingleton(); var ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged); for (int i = 0; i < config.SphereCount; i++) { var entity = ecb.Instantiate(config.SpherePrefab); ecb.SetComponent(entity, new LocalTransform { Position = new float3(0, i * 2, 0), Rotation = quaternion.identity, Scale = 1 }); } // This system should only run once at startup. So it disables itself after one update. state.Enabled = false; } } ``` -------------------------------- ### AllHitsCollector.NumHits Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.AllHitsCollector-1.html Gets the total number of hits that have been collected. ```APIDOC ## NumHits { get; } ### Description Gets the number of hits. ### Property Value - **int** - The total number of hits. ``` -------------------------------- ### Get Collision Filter Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ConvexCollider.html Retrieves the collision filter associated with the collider. ```APIDOC ## GetCollisionFilter() ### Description Gets the collision filter. ### Method `public CollisionFilter GetCollisionFilter()` ### Returns - **CollisionFilter** - The collision filter. ``` -------------------------------- ### CollisionWorld.StaticBodies Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CollisionWorld.html Gets the NativeArray of static rigid bodies in the collision world. ```APIDOC ## CollisionWorld.StaticBodies ### Description Gets the static bodies. ### Property Value - **NativeArray** - The static bodies. ``` -------------------------------- ### CollisionWorld.NumStaticBodies Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CollisionWorld.html Gets the total number of static bodies in the collision world. ```APIDOC ## CollisionWorld.NumStaticBodies ### Description Gets the number of static bodies. ### Property Value - **int** - The total number of static bodies. ``` -------------------------------- ### AddExistingSystemsToUpdate Method Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.CustomPhysicsSystemGroupBase.html This protected virtual method allows subclasses to specify additional managed systems to be copied into the custom physics world. It is called the first time OnUpdate runs. ```APIDOC ## AddExistingSystemsToUpdate(List systems) ### Description An interface method to specify an additional set of managed systems which are copied to the custom physics world. This will be called the first time OnUpdate runs. ### Parameters - **systems** (List) - The systems. ``` -------------------------------- ### PhysicsWorldSingleton Access Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.PhysicsWorldSingleton.html Demonstrates how to access the PhysicsWorldSingleton for read-only or read-write operations within a Unity system. ```APIDOC ## Accessing PhysicsWorldSingleton Use `(SystemBase|SystemAPI|EntityQuery).GetSingleton()` for read-only access. Use `(SystemBase|SystemAPI|EntityQuery).GetSingletonRW()` for read-write access. ``` -------------------------------- ### CollisionWorld.NumDynamicBodies Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CollisionWorld.html Gets the total number of dynamic bodies in the collision world. ```APIDOC ## CollisionWorld.NumDynamicBodies ### Description Gets the number of dynamic bodies. ### Property Value - **int** - The total number of dynamic bodies. ``` -------------------------------- ### CollisionWorld.DynamicBodies Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CollisionWorld.html Gets the NativeArray of dynamic rigid bodies in the collision world. ```APIDOC ## CollisionWorld.DynamicBodies ### Description Gets the dynamic bodies. ### Property Value - **NativeArray** - The dynamic bodies. ``` -------------------------------- ### CompleteDependencyBeforeRW Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.html Completes the dependency chain required for read and write access to components, ensuring all read and write dependencies are resolved. ```APIDOC ## CompleteDependencyBeforeRW(ref SystemState state) ### Description Completes the dependency chain required for this component to have read and write access. ### Parameters - **state** (SystemState) - The SystemState containing an EntityManager storing all dependencies. ### Returns - **void** ``` -------------------------------- ### Initialize Sphere Collider Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.SphereCollider.html Initializes the sphere collider, enabling it to be created on the stack. ```APIDOC ## Initialize(SphereGeometry, CollisionFilter, Material) ### Description Initializes the sphere collider with the specified geometry, collision filter, and material. ### Method `public void Initialize(SphereGeometry geometry, CollisionFilter filter, Material material)` ### Parameters - **geometry** (SphereGeometry) - The geometry of the sphere. - **filter** (CollisionFilter) - Specifies the filter. - **material** (Material) - The material of the collider. ``` -------------------------------- ### GetRagdollPrimaryConeAndTwistRange Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Extensions.JointComponentExtensions.html Gets the range of motion for a ragdoll primary cone PhysicsJoint. ```APIDOC ## GetRagdollPrimaryConeAndTwistRange ### Description Gets the range of motion for a ragdoll primary cone PhysicsJoint created using CreateRagdoll(BodyFrame, BodyFrame, float, FloatRange, FloatRange, out PhysicsJoint, out PhysicsJoint). ### Method Signature public static void GetRagdollPrimaryConeAndTwistRange(this in PhysicsJoint joint, out float maxConeAngle, out Math.FloatRange angularTwistRange) ### Parameters - **joint** (PhysicsJoint) - The joint. - **maxConeAngle** (out float) - Half angle of the primary cone, which defines the maximum possible range of motion in which the primary axis is restricted. - **angularTwistRange** (out Math.FloatRange) - The range of angular motion for twisting around the primary axis within the region defined by the primary and perpendicular cones. This range is usually symmetrical. ``` -------------------------------- ### GetRagdollPerpendicularConeRange Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Extensions.JointComponentExtensions.html Gets the range of motion for a ragdoll perpendicular cone PhysicsJoint. ```APIDOC ## GetRagdollPerpendicularConeRange ### Description Gets the range of motion for a ragdoll perpendicular cone PhysicsJoint created using CreateRagdoll(BodyFrame, BodyFrame, float, FloatRange, FloatRange, out PhysicsJoint, out PhysicsJoint). ### Method Signature public static Math.FloatRange GetRagdollPerpendicularConeRange(this in PhysicsJoint joint) ### Parameters - **joint** (PhysicsJoint) - The joint. ### Returns - **Math.FloatRange** - The range of angular motion defining the cones perpendicular to the primary cone, between which the primary axis may swing. This range may be asymmetrical. ``` -------------------------------- ### Schedule(T, SimulationSingleton, ref PhysicsWorld, JobHandle) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.IJacobiansJobExtensions.html Provides a default scheduling implementation for jobs that implement IJacobiansJobBase. This extension method simplifies the process of scheduling physics jobs by handling dependencies and world state. ```APIDOC ## Schedule(T jobData, SimulationSingleton simulationSingleton, ref PhysicsWorld world, JobHandle inputDeps) ### Description Default Schedule() implementation for IJacobiansJob. ### Method ```csharp public static JobHandle Schedule(this T jobData, SimulationSingleton simulationSingleton, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, IJacobiansJobBase ``` ### Parameters * **jobData** (T) - The jobData to act on. * **simulationSingleton** (SimulationSingleton) - The simulation singleton. * **world** (PhysicsWorld) - [in,out] The world. * **inputDeps** (JobHandle) - The input deps. ### Returns * **JobHandle**: A JobHandle. ``` -------------------------------- ### GetPrismaticRange Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Extensions.JointComponentExtensions.html Gets the range of motion for a PhysicsJoint created using CreatePrismatic. ```APIDOC ## GetPrismaticRange ### Description Gets the range of motion for a PhysicsJoint created using CreatePrismatic(BodyFrame, BodyFrame, FloatRange). ### Method Signature public static Math.FloatRange GetPrismaticRange(this in PhysicsJoint joint) ### Parameters - **joint** (PhysicsJoint) - The joint. ### Returns - **Math.FloatRange** - The minimum required and maximum possible distance between the two anchor points along their aligned axes. ``` -------------------------------- ### PhysicsWorld Constructor Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.PhysicsWorld.html Constructs a PhysicsWorld with a specified number of uninitialized static bodies, dynamic bodies, and joints. Use this to pre-allocate space for physics entities. ```csharp public PhysicsWorld(int numStaticBodies, int numDynamicBodies, int numJoints) ``` -------------------------------- ### BuildLocalToWorld Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.GraphicsIntegration.GraphicalSmoothingUtility.html Constructs a LocalToWorld matrix for a rigid body's graphical representation, potentially incorporating a post-transform matrix. ```APIDOC ## BuildLocalToWorld ### Description Construct a `LocalToWorld` matrix for a rigid body's graphical representation. ### Method Signature ```csharp public static LocalToWorld BuildLocalToWorld(int i, RigidTransform transform, float uniformScale, bool hasPostTransformMatrix, NativeArray postTransformMatrices) ``` ### Parameters #### Path Parameters - **i** (int) - The index of the rigid body in the chunk. Used to look up the body's Unity.Transforms.PostTransformMatrix component in the provided `postTransformMatrices` array, if any (see `hasPostTransformMatrix` parameter). - **transform** (RigidTransform) - The body's world space transform. - **uniformScale** (float) - The body's uniform scale. - **hasPostTransformMatrix** (bool) - `true` if the rigid body has a Unity.Transforms.PostTransformMatrix component; otherwise, `false`. - **postTransformMatrices** (NativeArray) - The array of post transform matrices in the chunk. ### Returns #### Success Response - **LocalToWorld** - A LocalToWorld matrix to use in place of those produced by default. ``` -------------------------------- ### GetLimitedHingeRange Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Extensions.JointComponentExtensions.html Gets the range of motion for a PhysicsJoint created using CreateLimitedHinge. ```APIDOC ## GetLimitedHingeRange ### Description Gets the range of motion for a PhysicsJoint created using CreateLimitedHinge(BodyFrame, BodyFrame, FloatRange). ### Method Signature public static Math.FloatRange GetLimitedHingeRange(this in PhysicsJoint joint) ### Parameters - **joint** (PhysicsJoint) - The joint. ### Returns - **Math.FloatRange** - The minimum required and maximum possible angle of rotation about the aligned axes. ``` -------------------------------- ### GetLimitedDistanceRange Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Extensions.JointComponentExtensions.html Gets the range of motion for a PhysicsJoint created using CreateLimitedDistance. ```APIDOC ## GetLimitedDistanceRange ### Description Gets the range of motion for a PhysicsJoint created using CreateLimitedDistance(float3, float3, FloatRange). ### Method Signature public static Math.FloatRange GetLimitedDistanceRange(this in PhysicsJoint joint) ### Parameters - **joint** (PhysicsJoint) - The joint. ### Returns - **Math.FloatRange** - The minimum required distance and maximum possible distance between the two anchor points. ``` -------------------------------- ### Clone Collision World (Basic) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.CollisionWorld.html Creates a shallow copy of the CollisionWorld. The Broadphase and rigid body data are deep copied, but colliders are shallow copied. ```csharp public CollisionWorld Clone() ``` -------------------------------- ### NumHits Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ClosestHitCollector-1.html Gets the total number of hits recorded by the collector. ```APIDOC ## NumHits ### Description Gets the number of hits. ### Property Value - **int** - The total number of hits (0 or 1). ``` -------------------------------- ### Solver.StabilizationData Constructor Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Solver.StabilizationData.html Initializes a new instance of the Solver.StabilizationData struct. Requires SimulationStepInput and SimulationContext objects. ```csharp public StabilizationData(SimulationStepInput stepInput, SimulationContext context) ``` -------------------------------- ### PhysicsWorldComponentHandles Constructor Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Systems.PhysicsWorldData.PhysicsWorldComponentHandles.html Initializes a new instance of the PhysicsWorldComponentHandles struct. ```APIDOC ## PhysicsWorldComponentHandles(ref SystemState) ### Description Constructor. ### Parameters - **systemState** (SystemState) - [in,out] State of the system. ``` -------------------------------- ### MaxFraction Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.ClosestHitCollector-1.html Gets or sets the maximum fraction for the physics query. ```APIDOC ## MaxFraction ### Description Gets or sets the maximum fraction. ### Property Value - **float** - The maximum fraction. ``` -------------------------------- ### Scale Property Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.RigidBodyAspect.html Gets or sets the uniform scale of the rigid body. ```APIDOC ## Scale ### Description Gets or sets the uniform scale of the rigid body. ### Property Value - **float**: The scale. ``` -------------------------------- ### Build LocalToWorld Matrix - Unity Physics Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.GraphicsIntegration.GraphicalSmoothingUtility.html Constructs a LocalToWorld matrix for a rigid body's graphical representation. Use this when a rigid body has a PostTransformMatrix component and you need to override the default matrix generation. ```csharp public static LocalToWorld BuildLocalToWorld(int i, RigidTransform transform, float uniformScale, bool hasPostTransformMatrix, NativeArray postTransformMatrices) ``` -------------------------------- ### PhysicsStep Struct Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.PhysicsStep.html Describes the parameters available for configuring a physics simulation step. ```APIDOC ## Struct PhysicsStep Parameters describing how to step the physics world. If none is present in the scene, default values will be used. ### Fields #### CollisionTolerance The collision tolerance specifies the minimum distance required for contacts between rigid bodies to be created. This value can be increased if undesired collision tunneling is observed in the simulation. - **Type**: float #### Default (Immutable) the default. - **Type**: PhysicsStep #### Gravity The gravity. - **Type**: float3 #### IncrementalDynamicBroadphase Flag indicating whether the dynamic broadphase is built incrementally. Enabling this option will update the dynamic broadphase incrementally whenever changes between simulation steps occur, potentially leading to time savings for cases with many dynamic rigid bodies that don't move or otherwise change. - **Type**: bool #### IncrementalStaticBroadphase Flag indicating whether the static broadphase is built incrementally. Enabling this option will update the static broadphase incrementally whenever changes between simulation steps occur, potentially leading to time savings for cases with many static rigid bodies that don't move or otherwise change. - **Type**: bool #### MaxDynamicDepenetrationVelocity Maximum relative velocity that can be produced when separating intersecting dynamic rigid bodies. - **Type**: float #### MaxStaticDepenetrationVelocity Maximum relative velocity that can be produced when separating dynamic rigid bodies intersecting with static rigid bodies. - **Type**: float #### MultiThreaded Flag indicating whether the simulation will run multi-threaded. - **Type**: byte #### SimulationType Type of the simulation. - **Type**: SimulationType #### SolverIterationCount Number of Gauss-Seidel solver iterations. - **Type**: int #### SolverStabilizationHeuristicSettings The global solver stabilization heuristic settings. - **Type**: Solver.StabilizationHeuristicSettings #### SubstepCount Number of substeps. - **Type**: int #### SynchronizeCollisionWorld Whether to synchronize collision world after physics step to enable precise query results. Note that `BuildPhysicsWorld` will do this work on the following frame anyway, so only use this option when another system must know about the results of the simulation before the end of the frame (e.g., to destroy or create some other body that must be present in the following frame). In most cases, tolerating a frame of latency is easier to work with and is better for performance. - **Type**: byte ``` -------------------------------- ### Resolve Method Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.Aspects.ColliderAspect.TypeHandle.html Get the enclosing aspect's ColliderAspect.ResolvedChunk from an ArchetypeChunk. ```APIDOC public ColliderAspect.ResolvedChunk Resolve(ArchetypeChunk chunk) ``` -------------------------------- ### Schedule(T, SimulationSingleton, ref PhysicsWorld, JobHandle) Source: https://docs.unity3d.com/Packages/com.unity.physics%401.4/api/Unity.Physics.IBodyPairsJobExtensions.html Schedules a job that operates on body pairs, providing a default implementation for IBodyPairsJob. ```APIDOC ## Schedule(T, SimulationSingleton, ref PhysicsWorld, JobHandle) ### Description Default Schedule() implementation for IBodyPairsJob. ### Method `public static JobHandle Schedule(this T jobData, SimulationSingleton simulationSingleton, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, IBodyPairsJobBase` ### Parameters #### Path Parameters * **jobData** (T) - The jobData to act on. * **simulationSingleton** (SimulationSingleton) - The simulation singleton. * **world** (PhysicsWorld) - [in,out] The world. * **inputDeps** (JobHandle) - The input deps. ### Returns * **JobHandle**: A JobHandle. ```