Search Unity

Best way to call EnqueueCallback (without a system)?

Discussion in 'Physics for ECS' started by Mr-Mechanical, Dec 6, 2019.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    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))]?
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    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()
    .
     
    Mr-Mechanical likes this.