Skip to content

Commit 4a7d0ea

Browse files
author
Unity Technologies
committed
com.unity.physics@1.4.0-pre.4
## [1.4.0-pre.4] - 2025-07-11 ### Added * New `TerrainCollider.Create` function variant that allows customizing the triangulation pattern of the created terrain collider's cells by flipping their inner diagonal edge, thus enabling users to align the physics collision representation with their visual terrain mesh. * A newly introduced Detailed Static Mesh Collision feature enables enhanced collision detection precision for interactions with static meshes, effectively eliminating ghost collisions that can otherwise frequently occur in the presence of small mesh triangles or at high motion speeds. To enable the feature select the "Detailed Static Mesh Collision" option in the "Advanced" section of your custom `PhysicsShapeAuthoring` component, or, If you are using built-in `Collider` components, add the new `DetailedStaticMeshCollisionAuthoring` component alongside your collider. For runtime-generated colliders, please use the `EnableDetailedStaticMeshCollision` parameter in the physics material. * Integrity checks for incremental broadphase. When integrity checks are enabled (see Project Settings -> Physics -> Unity Physics -> Enable Integrity Checks) the `PhysicsTemporalCoherenceInfo` component data of rigid body entities is validated against the internal state of the broadphase, to make sure the data is as expected. This allows detecting unexpected external modifications to this important bookkeeping data. ### Changed * Parallelize jacobian updates for substepping without consideration of solver phases since there are no data dependencies * Safer access to nodes in `BoundingVolumeHierarchy` of broadphase, ensuring there are no out-of-bounds accesses. ### Fixed * Fixed a crash when scheduling an IBodyPairsJob and an IJacobiansJob in a situation without any body pairs or jacobians present in the simulation. * Division by zero errors causing NaN values when a Capsule degenerates into a Sphere (occurs when Height = 2*Radius) * ConvexHull connectivity for flat convex colliders * Referenced prefabs in bakers with built-in joints incorrectly displayed the anchor position when the `Auto Configure Connected Anchor` flag was enabled. * Correctly compute the expansion space for convex / composite collision queries, preventing missed collisions in certain cases. * Pass the "Build Static Tree" flag to tree build job in single-threaded version of static tree update. * A specific use case has been patched which applies only to Mac Silicon devices using editor version 2022.3 and when a negative scale is used in the transform of a BoxCollider: The transform calculation from localToWorld matrix to quaternion doesn't return the correct value due to differences in the calculation of rsqrt(x). This is exhibited as BoxGeometry orientations returning a strange quaternion value when the scale is negative. This bug has been fixed in the editor. * Prevent invalid entries in incrementally built broadphase if it was built non-incrementally previously. ### Security
1 parent 45f878d commit 4a7d0ea

File tree

124 files changed

+2128
-746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+2128
-746
lines changed

CHANGELOG.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@ uid: unity-physics-changelog
44

55
# Changelog
66

7+
## [1.4.0-pre.4] - 2025-07-11
8+
9+
### Added
10+
11+
* New `TerrainCollider.Create` function variant that allows customizing the triangulation pattern of the created terrain collider's cells by flipping their inner diagonal edge, thus enabling users to align the physics collision representation with their visual terrain mesh.
12+
* A newly introduced Detailed Static Mesh Collision feature enables enhanced collision detection precision for interactions with static meshes, effectively eliminating ghost collisions that can otherwise frequently occur in the presence of small mesh triangles or at high motion speeds. To enable the feature select the "Detailed Static Mesh Collision" option in the "Advanced" section of your custom `PhysicsShapeAuthoring` component, or, If you are using built-in `Collider` components, add the new `DetailedStaticMeshCollisionAuthoring` component alongside your collider. For runtime-generated colliders, please use the `EnableDetailedStaticMeshCollision` parameter in the physics material.
13+
* Integrity checks for incremental broadphase. When integrity checks are enabled (see Project Settings -> Physics -> Unity Physics -> Enable Integrity Checks) the `PhysicsTemporalCoherenceInfo` component data of rigid body entities is validated against the internal state of the broadphase, to make sure the data is as expected. This allows detecting unexpected external modifications to this important bookkeeping data.
14+
15+
### Changed
16+
17+
* Parallelize jacobian updates for substepping without consideration of solver phases since there are no data dependencies
18+
* Safer access to nodes in `BoundingVolumeHierarchy` of broadphase, ensuring there are no out-of-bounds accesses.
19+
20+
### Fixed
21+
22+
* Fixed a crash when scheduling an IBodyPairsJob and an IJacobiansJob in a situation without any body pairs or jacobians present in the simulation.
23+
* Division by zero errors causing NaN values when a Capsule degenerates into a Sphere (occurs when Height = 2*Radius)
24+
* ConvexHull connectivity for flat convex colliders
25+
* Referenced prefabs in bakers with built-in joints incorrectly displayed the anchor position when the `Auto Configure Connected Anchor` flag was enabled.
26+
* Correctly compute the expansion space for convex / composite collision queries, preventing missed collisions in certain cases.
27+
* Pass the "Build Static Tree" flag to tree build job in single-threaded version of static tree update.
28+
* A specific use case has been patched which applies only to Mac Silicon devices using editor version 2022.3 and when a negative scale is used in the transform of a BoxCollider: The transform calculation from localToWorld matrix to quaternion doesn't return the correct value due to differences in the calculation of rsqrt(x). This is exhibited as BoxGeometry orientations returning a strange quaternion value when the scale is negative. This bug has been fixed in the editor.
29+
* Prevent invalid entries in incrementally built broadphase if it was built non-incrementally previously.
30+
31+
### Security
32+
33+
734
## [1.4.0-pre.3] - 2025-06-06
835

936

@@ -507,7 +534,7 @@ uid: unity-physics-changelog
507534

508535
### Upgrade guide
509536

510-
* The physics pipeline has been reworked. - `PhysicsSystemGroup` is introduced. It is a `ComponentSystemGroup` that covers all physics jobs. It consists of `PhysicsInitializeGroup`, `PhysicsSimulationGroup`, and `ExportPhysicsWorld`. `PhysicsSimulationGroup` further consists of `PhysicsCreateBodyPairsGroup`, `PhysicsCreateContactsGroup`, `PhysicsCreateJacobiansGroup`, `PhysicsSolveAndIntegrateGroup` which run in that order. See [documentation](xref:interacting-with-physics) for details. - `StepPhysicsWorld` and `EndFramePhysicsSystem` systems have been removed, `BuildPhysicsWorld` has been moved to `PhysicsInitializeGroup`: - If you had `Update(Before|After)StepPhysicsWorld`, replace it with: `[UpdateInGroup(typeof(PhysicsSystemGroup))][Update(After|Before)(typeof(PhysicsSimulationGroup))]`. - If you had `Update(Before|After)BuildPhysicsWorld`, replace it with: `[UpdateBefore(typeof(PhysicsSystemGroup))]` or `[UpdateInGroup(typeof(PhysicsSystemGroup))][UpdateAfter(typeof(PhysicsInitializeGroup))]` - If you had `Update(Before|After)ExportPhysicsWorld` replace it with: `[UpdateInGroup(typeof(PhysicsSystemGroup))][UpdateBefore(typeof(ExportPhysicsWorld))]` or `[UpdateAfter(typeof(PhysicsSystemGroup))]` - If you had `[Update(Before|After)EndFramePhysicsSystem]` replace it with: `[UpdateAfter(typeof(PhysicsSystemGroup))]` - If you had combination of those (e.g. `[UpdateAfter(typeof(BuildPhysicsWorld))][UpdateBefore(typeof(StepPhysicsWorld))`) take a look at the diagram in [documentation](xref:interacting-with-physics). - All new systems are unmanaged, which means that they are more efficient, and their `OnUpdate()` is Burst friendly. You shouldn't call `World.GetOrCreateSystem<AnyPhysicsSystem>()` as of this release and should be using singletons (see below).
537+
* The physics pipeline has been reworked. - `PhysicsSystemGroup` is introduced. It is a `ComponentSystemGroup` that covers all physics jobs. It consists of `PhysicsInitializeGroup`, `PhysicsSimulationGroup`, and `ExportPhysicsWorld`. `PhysicsSimulationGroup` further consists of `PhysicsCreateBodyPairsGroup`, `PhysicsCreateContactsGroup`, `PhysicsCreateJacobiansGroup`, `PhysicsSolveAndIntegrateGroup` which run in that order. See [documentation](xref:interacting-with-physics) for details. - `StepPhysicsWorld` and `EndFramePhysicsSystem` systems have been removed, `BuildPhysicsWorld` has been moved to `PhysicsInitializeGroup`: - If you had `Update(Before|After)StepPhysicsWorld`, replace it with: `[UpdateInGroup(typeof(PhysicsSystemGroup))][Update(After|Before)(typeof(PhysicsSimulationGroup))]`. - If you had `Update(Before|After)BuildPhysicsWorld`, replace it with: `[UpdateBefore(typeof(PhysicsSystemGroup))]` or `[UpdateInGroup(typeof(PhysicsSystemGroup))][UpdateAfter(typeof(PhysicsInitializeGroup))]` - If you had `Update(Before|After)ExportPhysicsWorld` replace it with: `[UpdateInGroup(typeof(PhysicsSystemGroup))][UpdateBefore(typeof(ExportPhysicsWorld))]` or `[UpdateAfter(typeof(PhysicsSystemGroup))]` - If you had `[Update(Before|After)EndFramePhysicsSystem]` replace it with: `[UpdateAfter(typeof(PhysicsSystemGroup))]` - If you had combination of those (e.g. `[UpdateAfter(typeof(BuildPhysicsWorld))][UpdateBefore(typeof(StepPhysicsWorld))`) take a look at the diagram in [documentation](xref:interacting-with-physics). - All new systems are unmanaged, which means that they are more efficient, and their `OnUpdate()` is Burst friendly. You shouldn't call `World.GetOrCreateSystem<AnyPhysicsSystem>()` as of this release and should be using singletons (see below).
511538
* Retrieval of `PhysicsWorld` is achieved differently. Previously, it was necessary to get it directly from `BuildPhysicsWorld` system. Now, `PhysicsWorld` is retrieved by calling (`SystemAPI|SystemBase|EntityQuery`).GetSingleton<PhysicsWorldSingleton>().PhysicsWorld in case read-only access is required, and by calling (`SystemAPI|SystemBase|EntityQuery`).GetSingletonRW<PhysicsWorldSingleton>().PhysicsWorld in case of a read-write access. It is still possible to get the world from `BuildPhysicsWorld`, but is not recommended, as it can cause race conditions. This is only affecting the `PhysicsWorld` managed by the engine. Users still can create and manage their own `PhysicsWorld`. Check out [documentation](xref:interacting-with-physics) for more information.
512539
* Retrieval of `Simulation` is achieved differently. Previously, it was neccessary to get it directly from `StepPhysicsWorld` system. Now, `Simulation` is retrieved by calling (`SystemAPI|SystemBase|EntityQuery`).GetSingleton<SimulationSingleton>().AsSimulation() in case read-only access is required, and by calling (`SystemAPI|SystemBase|EntityQuery`).GetSingletonRW<SimulationSingleton>().AsSimulation() in case of read-write access. Check out [documentation](xref:interacting-with-physics) for more information.
513540
* The dependencies between physics systems now get sorted automatically as long as `GetSingleton<>()` approach is used for retrieving `PhysicsWorld` and `Simulation`. There is no need to call `RegisterPhysicsSystems(ReadOnly|ReadWrite)`, `AddInputDependency()` or `AddInputDependencyToComplete()` and these functions were removed.
@@ -722,7 +749,7 @@ uid: unity-physics-changelog
722749
* Added a `PhysicsMassOverride.SetVelocityToZero` field. If `PhysicsMassOverride.IsKinematic`, is a non-zero value, then a body's mass and inertia are made infinite, though it's motion will still be integrated. If `PhysicsMassOverride.SetVelocityToZero` is also a non-zero value, the kinematic body will ignore the values in the associated `PhysicsVelocity` component and no longer move.
723750

724751
* Run-Time Behavior
725-
* If a body has infinite mass and/or inertia, then linear and/or angular damping will no longer be applied respectively.
752+
* If a body has infinite mass and/or inertia, then linear and/or angular damping will no longer be applied respectively.
726753

727754
### Fixes
728755

@@ -754,7 +781,7 @@ uid: unity-physics-changelog
754781
* Removed `ModifiableJacobianHeader.HasColliderKeys`, `ModifiableJacobianHeader.ColliderKeyA` and `ModifiableJacobianHeader.ColliderKeyB` as they are not meant to be read by users, but to fill the data for collision events.
755782
* Removed `SimulationCallbacks.Phase.PostSolveJacobians` as it doesn't have real use cases and it's causing inconsistencies between the two engines. Instead, users should schedule their jobs after `StepPhysicsWorld` and before `ExportPhysicsWorld` to achieve a similar effect.
756783
* Added `ClampToMaxLength()` to `Unity.Physics.Math`, which reduces the length of specified `float3` vector to specified maxLength if it was bigger.
757-
* `ColliderCastHit` and `DistanceHit` now have `QueryColliderKey` field. If the input of `ColliderCast` or `ColliderDistance` queries contains a non-convex collider, this field will contain the collider key of the input collider. Otherwise, its value will be `ColliderKey.Empty`.
784+
* `ColliderCastHit` and `DistanceHit` now have `QueryColliderKey` field. If the input of `ColliderCast` or `ColliderDistance` queries contains a non-convex collider, this field will contain the collider key of the input collider. Otherwise, its value will be `ColliderKey.Empty`.
758785
* Removed `AddInputDependency()` and `GetOutputDependency()` from all physics systems as dependencies are now handled in a different way (see below).
759786
* Added `RegisterPhysicsRuntimeSystemReadOnly()` and `RegisterPhysicsRuntimeSystemReadWrite()` that are both extension methods for `SystemBase` and are used to declare interaction with the runtime physics data (stored in PhysicsWorld). One should call one of these in their system's `OnStartRunning()` (using `this.RegisterPhysicsRuntimeSystemReadOnly()` or `this.RegisterPhysicsRuntimeSystemReadWrite()`) to declare interaction with the physics data, which will translate to automatic data dependencies being included in the `SystemBase.Dependency` property of any system.
760787
* Previously internal functions in `ColliderKey`, `ColliderKeyPath` and `ChildCollider` are now public to aid the traversal of a `Collider` hierarchy.
@@ -766,7 +793,7 @@ uid: unity-physics-changelog
766793
* Added a `PhysicsRenderEntity` component data. This is primarily used for populating a `CompoundCollider.Child.Entity` field where there was no graphical representation on the same GameObject that has a `PhysicsShapeAuthoring` component.
767794

768795
* Run-Time Behavior
769-
* `ColliderDistance` and `ColliderCast` queries now support non-convex input colliders (Compounds, Meshes and Terrains).
796+
* `ColliderDistance` and `ColliderCast` queries now support non-convex input colliders (Compounds, Meshes and Terrains).
770797

771798
* Authoring/Conversion Behavior
772799

@@ -838,7 +865,7 @@ uid: unity-physics-changelog
838865
* Authoring/Conversion API
839866

840867
* Run-Time Behavior
841-
* `ExportPhysicsWorld` system should now only get updated when there is at least one entity satisfying `BuildPhysicsWorld.DynamicEntityGroup` entity query.
868+
* `ExportPhysicsWorld` system should now only get updated when there is at least one entity satisfying `BuildPhysicsWorld.DynamicEntityGroup` entity query.
842869

843870
* Authoring/Conversion Behavior
844871

@@ -868,7 +895,7 @@ uid: unity-physics-changelog
868895
* Added the `TerrainCollider.Filter` setter
869896
* Removed the `CompoundCollider.Filter` setter as it was doing the wrong thing (composite collider filters should be the union of their children)
870897
* Added `BuildPhysicsWorld.AddDependencyToComplete()` which takes a job dependency that the `BuildPhysicsWorld` system should complete immediately in its `OnUpdate()` call (before scheduling new jobs). The reason is that this system does reallocations in the `OnUpdate()` immediately (not in jobs), and any previous jobs that are being run before this system could rely on that data being reallocated. This way, these jobs can provide their dependency to `BuildPhysicsWorld` and make sure it will wait until they are finished before doing the reallocations.
871-
* Added the option to provide a custom explosion filter in 'PhysicsVelocity.ApplyExplosionForce'.
898+
* Added the option to provide a custom explosion filter in 'PhysicsVelocity.ApplyExplosionForce'.
872899

873900
* Authoring/Conversion API
874901

@@ -953,8 +980,8 @@ uid: unity-physics-changelog
953980
* `Solver.ApplyGravityAndCopyInputVelocities()` passing `NativeArray<MotionData>`
954981
* `Solver.SolveJacobians()` not passing explicit `StabilizationData`
955982
* Added `JointType.LimitedDegreeOfFreedom` and associated creation and control functions
956-
* Added `Aabb.Intersect()` function
957-
* Added `PhysicsComponentExtensions.GetEffectiveMass()`
983+
* Added `Aabb.Intersect()` function
984+
* Added `PhysicsComponentExtensions.GetEffectiveMass()`
958985

959986
* Authoring/Conversion API
960987
* Removed the following expired members/types:

Documentation~/attract-body.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Interacting with rigid bodies can be done using scripts. For example to alter the velocity of a body, you can query for its `PhysicsVelocity` and set new values. Let's make an example that attracts all bodies to a single point.
44

5-
First, we will create a `MonoBehaviour` script file called `TargetAuthoring.cs` (with two values, one float and one GameObject) and attach it to the Sphere GameObject. This will allow us to input data values from the inspector. Then, we need to add an `IComponentData` struct named `Target` and as well as a `Baker` called `TargetAuthoringBaker` and bridge the values from the `TargetAuthoring` with the `Target`.
5+
First, we will create a `MonoBehaviour` script file called `TargetAuthoring.cs` (with two values, one float and one GameObject) and attach it to the Sphere GameObject. This will allow us to input data values from the inspector. Then, we need to add an `IComponentData` struct named `Target` and as well as a `Baker` called `TargetAuthoringBaker` and bridge the values from the `TargetAuthoring` with the `Target`.
66

77
```csharp
88
using Unity.Entities;
@@ -37,7 +37,7 @@ public class TargetAuthoringBaker : Baker<TargetAuthoring>
3737
3838
Now, we need do something similar to be able run the logic inside the `ISystem`. Create another `MonoBehaviour` script file called `MovingBodyAuthoring.cs` but instead of authoring the same values than before, we will use a float for velocity magnitude.
3939

40-
Inside the OnUpdate within `ISystem`, let's use the new idiomatic `foreach()` to query for all the entities with `MovingBody`. Then we can run the command to calculate the relative distance between the `Target` position and the `MovingBody` entity. Finally, we compare if the distance is smaller than the MaxDistance value, if so the `PhysicsVelocity` will be altered and the entity will start moving towards the target position.
40+
Inside the OnUpdate within `ISystem`, let's use the new idiomatic `foreach()` to query for all the entities with `MovingBody`. Then we can run the command to calculate the relative distance between the `Target` position and the `MovingBody` entity. Finally, we compare if the distance is smaller than the MaxDistance value, if so the `PhysicsVelocity` will be altered and the entity will start moving towards the target position.
4141

4242
```csharp
4343
using Unity.Entities;
@@ -125,9 +125,9 @@ public static void ApplyImpulse(ref PhysicsVelocity pv, PhysicsMass pm,
125125
// Calculate point impulse
126126
var worldFromEntity = new RigidTransform(r.Value, t.Value);
127127
var worldFromMotion = math.mul(worldFromEntity, pm.Transform);
128-
float3 angularImpulseWorldSpace =
128+
float3 angularImpulseWorldSpace =
129129
math.cross(point - worldFromMotion.pos, impulse);
130-
float3 angularImpulseInertiaSpace =
130+
float3 angularImpulseInertiaSpace =
131131
math.rotate(math.inverse(worldFromMotion.rot), angularImpulseWorldSpace);
132132

133133
pv.Angular += angularImpulseInertiaSpace * pm.InverseInertia;

Documentation~/authoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Authoring
1+
# Authoring
22

33
You can edit your physics simulation and author your sub-scenes using the following authoring components.
44

Documentation~/built-in-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Unity Physics supports the built-in Unity Engine Physics components for sub-scen
1515
* [FixedJoint](xref:class-FixedJoint)
1616
* [HingeJoint](xref:class-HingeJoint)
1717
* [Ragdolls](xref:ragdoll-physics-section)
18-
* See the [Unity Physics Samples](https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/PhysicsSamples) project for ragdoll demo scenes.
18+
* See the [Unity Physics Samples](https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/PhysicsSamples) project for ragdoll demo scenes.
1919

2020
Alternatively, you can use the custom physics components for authoring your simulation.
2121
Refer to the [Custom Physics Authoring](custom-samples-physics-components.md) section for more details.

Documentation~/collision-queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ This section lists some simple examples for various queries. The examples for Ra
171171
}
172172
return Entity.Null;
173173
}
174-
```
174+
```
175175

176176
That will return the closest hit Entity along the desired ray. You can inspect the results of `RaycastHit` for more information such as hit position and normal etc.
177177

Documentation~/component-debug-display.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ partial struct RuntimePhysicsDebugDisplayDataManager : ISystem
5959

6060
if (Input.GetKeyDown(KeyCode.Alpha1))
6161
debugDisplayData.DrawColliders ^= 1;
62-
62+
6363
if (Input.GetKeyDown(KeyCode.Alpha2))
6464
debugDisplayData.DrawColliderEdges ^= 1;
65-
65+
6666
if (Input.GetKeyDown(KeyCode.Alpha3))
6767
debugDisplayData.DrawContacts ^= 1;
6868

@@ -76,7 +76,7 @@ partial struct RuntimePhysicsDebugDisplayDataManager : ISystem
7676
//debugDisplayData.ColliderEdgesDisplayMode = (PhysicsDebugDisplayMode)((byte)debugDisplayData.ColliderEdgesDisplayMode ^ 1);
7777
//debugDisplayData.ColliderAabbDisplayMode = (PhysicsDebugDisplayMode)((byte)debugDisplayData.ColliderAabbDisplayMode ^ 1);
7878
//debugDisplayData.ColliderDisplayMode = (PhysicsDebugDisplayMode)((byte)debugDisplayData.ColliderDisplayMode ^ 1);
79-
79+
8080
SystemAPI.SetSingleton(debugDisplayData);
8181
}
8282
}

Documentation~/component-step.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# The Physics Step authoring component
1+
# The Physics Step authoring component
22

33
To control Unity Physics settings, you need a `Physics Step` authoring component. As usual when working with **Entities**, a **SubScene** is necessary when adding the `Physics Step` authoring component. Only one instance of this component should be present in a scene as it will apply to the whole physics simulation.
44

0 commit comments

Comments
 (0)