Search Unity

Entity Index and Determinism

Discussion in 'Physics for ECS' started by redwren, Jul 8, 2021.

  1. redwren

    redwren

    Joined:
    Aug 2, 2019
    Posts:
    69
    I know entity ordering affects determinism with Unity Physics, but do entity indicies themselves affect determinism? If two worlds create entities in the same order, but one creates additional (non physics) entities, will Unity Physics produce a deterministic result?
     
    Last edited: Jul 9, 2021
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Hmm, interesting question. I haven't tested this. I'd say this is a general ordering/determination question rather then specific to physics.
    In BuildPhysicsWorld there is a CreateRigidBodies job which uses the DynamicEntityGroup and StaticEntityGroup Entity Queries to establish order. Therefore, the entity order in BuildPhysicsWorld system (and ExportPhysicsWorld which uses the same queries) is going to be based on the general IJobEntityBatchWithIndex execution rules. This is also why changing structure in your own systems running in between BuildPhysicsWorld and ExportPhysicsWorld can be problematic. I don't believe the order is specifically effected by the Entity index directly, so you might get away with things. That said, the Entity index is likely highly correlated with, even if not causing, the order though.
    So, rather than the Entity Index, I'd be more concerned by the non physics entities changing how the physics entities are chunked, especially if they have component types in common with the physics entities, and you are adding and remove these components.
     
  3. redwren

    redwren

    Joined:
    Aug 2, 2019
    Posts:
    69
    Thanks. I could see the RemoveSwapBack calls when an entity is removed from a chunk causing an issue. Even if the physics entities are created in the same order, any structural change in that chunk that causes a remove/reinsert would swap the ordering.