The example that unity uses in the docs doesn't even compile, and when I try to make it work it throws an error.
https://docs.unity3d.com/Packages/com.unity.physics@1.3/manual/simulation-modification.html
This is what I did:
[UpdateInGroup(typeof(PhysicsSimulationGroup))]
[UpdateAfter(typeof(PhysicsCreateBodyPairsGroup))]
[UpdateBefore(typeof(PhysicsCreateContactsGroup))]
public partial struct DisableDynamicDynamicPairsSystem : ISystem
{
[BurstCompile]
struct DisableDynamicDynamicPairsJob : IBodyPairsJob
{
public int NumDynamicBodies;
public unsafe void Execute(ref ModifiableBodyPair pair)
{
// Disable the pair if it's dynamic-dynamic
bool isDynamicDynamic = pair.BodyIndexA < NumDynamicBodies && pair.BodyIndexB < NumDynamicBodies;
if (isDynamicDynamic)
{
pair.Disable();
}
}
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
PhysicsWorldSingleton worldSingleton = SystemAPI.GetSingletonRW<PhysicsWorldSingleton>().ValueRW;
SimulationSingleton simulationSingleton = SystemAPI.GetSingleton<SimulationSingleton>();
state.Dependency = new DisableDynamicDynamicPairsJob
{
NumDynamicBodies = worldSingleton.PhysicsWorld.NumDynamicBodies
}.Schedule(simulationSingleton, ref worldSingleton.PhysicsWorld,
state.Dependency);
}
}
If I add this before the DisableDynamicDynamicPairsJob, it works, but it will still throw ~30 errors when entering playmode.
state.Dependency = simulationSingleton.AsSimulation().StepContext.CreatePhasedDispatchPairsJobHandle;
However, I have no idea what this does and this is definitely not an actual fix, as I have to do an assembly reference to even get access to this function as it is internal to the Unity.Physics assembly