Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to do physics queries AFTER the physics update?

Discussion in 'Physics for ECS' started by PhilSA, Apr 26, 2020.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I need to do a CalculateDistance after all the physics bodies have moved with their velocities, but before the end of the frame. I was expecting to find a ExportPhysicsWorld.PhysicsWorld which I can call CalculateDistance from, but it doesn't seem to be there (no public PhysicsWorld in that system)

    Right now I have a system that updates after EndframePhysicsSystem, and uses BuildPhysicsSystem.PhysicsWorld to do a CalculateDistance. The colliders seem to not be properly updated at that point
     
    Last edited: Apr 26, 2020
  2. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    70
    The collision world is updated only in BuildPhysicsSystem by default, so that you can do queries in parallel with simulation. Therefore queries will hit the "previous" world state. However you can opt into ExportPhysicsSystem also updating the collision world by setting SimulationStepInput.SynchronizeCollisionWorld to true.
     
    PhilSA likes this.
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    This sounds like exactly what I need. However, looking at the code, it seems there is no public variable in StepPhysicsWorld that would let us set this to true


    Is the only way to do this currently to disable StepPhysicsWorld system and write our own copy nstead? (or edit physics package source code?)

    If so, this would be pretty unfortunate for an asset store project that needs to rely on this
     
  4. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Ah, yes, that's a bit unlucky. However, SynchronizeCollisionWorld is something you can do on your own in a system you would plug in after StepPhysicsWorld and before ExportPhysicsWorld, just call CollisionWorld.ScheduleUpdateDynamicTree(), that's all it does anyway.

    I'll work on exposing it properly for next release.
     
    Last edited: Apr 27, 2020