By default, systems belong to the
SimulationSystemGroup, which is not called with fixed frame-rate frequency. Nested within it is another group called the
FixedStepSimulationSystemGroup. As its name implies, the latter group is fixed, making it ideal for physics-related processing. Thus, here's a code snippet for creating physics-related systems at a fixed step:
public class SomePhysicalSystem : SystemBase
BuildPhysicsWorld buildPhysicsWorld => World.GetOrCreateSystem<BuildPhysicsWorld>();
protected override void OnUpdate()
.ForEach((Entity entity, ref PhysicsVelocity velocity, ref PhysicsMass mass) =>
Note the use of the
UpdateBefore attributes to ensure the correct system update order.
There is also a need to add the current dependency as input to the
BuildPhysicsWorld, because, otherwise, that built-in system may not wait for physics-related changes that could have been prompted by custom processing.
To stay informed on current best practices with Unity DOTS, I recommend watching Unity's official EntityComponentSystemSamples GitHub repository, which includes physics demos.