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.

Resolved You must include Broadphase: prepareStaticBodyDataJob as a dependency of the newly scheduled job.

Discussion in 'Physics for ECS' started by Samsle, Mar 21, 2022.

  1. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    86
    Hello,
    does someone know how I can get the dependency of
    BuildPhysicsWorld
    to add it to my lambda job as dependency?
    Getting the dependency via
    buildPhysicsWorld.GetOutputDependency()
    is deprecated and not allowed anymore. It tells I should use
    RegisterPhysicsRuntimeSystemReadWrite/Only()
    , but it still throws me the error when running my system
    And as far as I could figure out,
    prepareStaticBodyDataJob
    belongs to
    BuildPhysicsWorld
    . So I have no idea how I can get that dependency.. :confused:

    Code (CSharp):
    1. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    2. [UpdateAfter(typeof(BuildPhysicsWorld))]
    3. [UpdateBefore(typeof(StepPhysicsWorld))]
    4. public partial class PredictionSwitchingApplyInputSystem : SystemBase
    5. {
    6.     private GhostPredictionSystemGroup m_GhostPredictionSystemGroup;
    7.     private BuildPhysicsWorld buildPhysicsWorld;
    8.  
    9.     protected override void OnCreate()
    10.     {
    11.         base.OnCreate();
    12.         m_GhostPredictionSystemGroup = World.GetExistingSystem<GhostPredictionSystemGroup>();
    13.         buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
    14.     }
    15.  
    16.     protected override void OnStartRunning() {
    17.         base.OnStartRunning();
    18.         buildPhysicsWorld.RegisterPhysicsRuntimeSystemReadWrite();
    19.     }
    20.  
    21.     protected override void OnUpdate()
    22.     {
    23.         var tick = m_GhostPredictionSystemGroup.PredictingTick;
    24.         PhysicsWorld world = this.buildPhysicsWorld.PhysicsWorld;
    25.  
    26.         Dependency = Entities
    27.             .ForEach(
    28.                 (
    29.                     Entity entity,
    30.                     DynamicBuffer<PredictionSwitchingInput> inputBuffer,
    31.                     in Translation translation,
    32.                     in PredictedGhostComponent prediction
    33.                 ) => {
    34.                     if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction)) {
    35.                         return;
    36.                     }
    37.  
    38.                     inputBuffer.GetDataAtTick(tick, out PredictionSwitchingInput input);
    39.  
    40.                     float3 impulse = new float3();
    41.  
    42.                     if (input.horizontal > 0)
    43.                         impulse = new float3(10, 0, 0);
    44.                     if (input.horizontal < 0)
    45.                         impulse = new float3(-10, 0, 0);
    46.                     if (input.vertical > 0)
    47.                         impulse = new float3(0, 0, 10);
    48.                     if (input.vertical < 0)
    49.                         impulse = new float3(0, 0, -10);
    50.  
    51.                     int ceIdx = world.GetRigidBodyIndex(entity);
    52.                     world.ApplyImpulse(ceIdx, impulse, translation.Value);
    53.                 }
    54.            ).Schedule(Dependency);
    55.     }
    56. }
     
    Last edited: Mar 21, 2022
    unity_9GTK35cY9R08zQ likes this.
  2. papopov

    papopov

    Joined:
    Jun 29, 2020
    Posts:
    32
    Calling this.RegisterPhysicsRuntimeSystemReadWrite() instead of buildPhysicsWorld.RegisterPhysicsRuntimeSystemReadWrite() should solve the problem.
     
    unity_9GTK35cY9R08zQ and Samsle like this.
  3. Samsle

    Samsle

    Joined:
    Mar 31, 2020
    Posts:
    86
    unity_9GTK35cY9R08zQ likes this.
  4. unity_9GTK35cY9R08zQ

    unity_9GTK35cY9R08zQ

    Joined:
    Sep 9, 2020
    Posts:
    6
    Thank you for your help people of the past, this solved my problem as well