Best way to call EnqueueCallback (without a system)?

In the some ECS samples I found I’ve seen EnqueueCallback being called with a system using [UpdateBefore(typeof(StepPhysicsWorld))]. Is there anyway to use EnqueueCallback without using a whole system and [UpdateBefore(typeof(StepPhysicsWorld))]?

You can call EnqueueCallback wherever you like, however StepPhysicsWorld clears the callback queue after stepping. Using your own system that updates before StepPhysicsWorld ensures that the callbacks are enqueued again before the next step (i.e. before StepPhysicsWorld.OnUpdate).
If you know you are not going to be changing the callback and are making Unity Physics a local package anyway you might want to think about tweaking com.unity.physics\Unity.Physics\ECS\Systems\StepPhysicsWorld.cs and commenting out the call to m_Callback.Clear().

1 Like