Search Unity

Question Physics dependency confusion... again?

Discussion in 'Physics for ECS' started by Thygrrr, Dec 6, 2020.

  1. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Hello! I could use some Unity.Physics 0.51-p2 help.

    I have a system that, in fixed time step, should move a bunch of Entities, some of them have PhysicsBodies.

    Regardless of what I do with the system, I get this error:
    Code (CSharp):
    1. System.InvalidOperationException: {0}
    2. Thrown from job: Unity.Physics.Systems.ExportPhysicsWorld.CheckTotalIntegrity
    3. This Exception was thrown from a job compiled with Burst, which has limited exception support.
    4. 0x00007ff9333c1299 (ef3928043c42a549af0d100dbd815c3) [unknown:0] Unity.Jobs.IJobExtensions.JobStruct`1<Unity.Physics.Systems.ExportPhysicsWorld.CheckTotalIntegrity>.Execute
    5. ...
    I get this regardless whether I run my system "bare" with only [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))], or trying to use the new AddInputDependency or AddInputDependencyToComplete calls:
    Code (CSharp):
    1.        protected override void OnUpdate()
    2.         {
    3.             Dependency = JobHandle.CombineDependencies(endFramePhysicsSystem.GetOutputDependency(), Dependency);
    4.      
    5.             Dependency = Entities.ForEach((ref Translation translation, in FloatingPosition floating) =>
    6.                 {
    7.                     translation.Value = (float3) (floating.position / Scale);
    8.                 }
    9.             ).ScheduleParallel(Dependency);
    10.      
    11.             buildPhysicsWorldSystem.AddInputDependency(Dependency);
    12.         }
    13.  
    My goals:
    1. my system should schedule parallel (there's actually a number of 6 or 7 systems that do similar tasks for disjunct groups of entities - currently these are commented out so they don't cause my issue - this is the simplest one)
    2. my system needs to not interfere with physics (because it would do some things that are at odds with the physics system - so ideally, running it before or after all physics, but still in fixed timestep

    A possibility is - I'd say they should run between EndFramePhysicsSystem and EndFixedStepSimulationEntityCommandBufferSystem but I have not the slightest idea how to do this. (a good primer on the way these magical dependencies are supposed to work would be really helpful - I can't glimpse it one bit from the documentation, which is odd, what am I missing here?)
     
    Last edited: Dec 6, 2020
  2. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Trying to make it run between ExportPhysicsWorldSystem and EndFramePhysicsSystem?

    Code (CSharp):
    1. protected override void OnUpdate()
    2. {
    3.     Dependency = JobHandle.CombineDependencies(exportPhysicsWorldSystem.GetOutputDependency(), Dependency);
    4.  
    5.     Dependency = Entities.ForEach((ref Translation translation, in FloatingPosition floating) =>
    6.         {
    7.             translation.Value = (float3) (floating.position / Scale);
    8.         }
    9.     ).ScheduleParallel(Dependency);
    10.  
    11.     endFramePhysicsSystem.AddInputDependency(Dependency);
    12. }
    This only gives me this, which at least tells me is I'm doing it at the wrong time, but why?
    upload_2020-12-6_12-11-3.png


    What am I getting wrong, I read this code as:
    - this system's job has a dependency on the output of ExportPhysicsWorldSystem, meaning it will run not before Export Physics World is complete.
    - EndFramePhysicsSystem is dependent on the output of this system's job, meaning it won't run before that's completed.
    - EndFramePhysicsSystem informs (in its own OnUpdate) BuildPhysicsWorld that it can't start before it is completed.

    So where's the gap? (it also doesn't help if I manually also tell BuildPhysicsWorld to wait for and complete my system's output dependency)
     
    Last edited: Dec 6, 2020
  3. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Code (CSharp):
    1.     [UpdateAfter(typeof(ExportPhysicsWorld))]
    2. ...
    3.     [UpdateBefore(typeof(BuildPhysicsWorld))]
    4.  
    So I guess we still need either one of those, regardless of job dependencies? Why? And why can't this system express all the dependencies needed, then?
     
  4. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    You need UpdateAfter ExportPhysicsWorld and UpdateBefore EndFramePhysicsSystem, in addition to the job handle things you already did. So you always need two of these and AddInputDependency()/GetOutputDependency() for the two of them.

    Edit: you need this update order to make sure the handles systems produce are valid at the point where you use them with input and output dependencies.
     
    BigRookGames and Thygrrr like this.
  5. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Yeah I'm slowly getting the hang of it, but I really hope Entities / Physics 1.0 will do away with that.

    THOSE dependencies... they would be finally a valid purpose for visual programming / node editing. In my humble opinion.
     
    Last edited: Dec 29, 2020