Search Unity

JobHandle.Complete() never runs the execute in the job

Discussion in 'Entity Component System' started by kstothert, Aug 11, 2019.

  1. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    Attempting to complete a job immediately after scheduling. The log outputs "before: false" and "after: true" but the execute is never called and never logs.

    Code (CSharp):
    1. struct StartJumpJob : ICollisionEventsJob {
    2.   [ReadOnly] public ComponentDataFromEntity<JumpInput> JumpInputGroup;
    3.   [ReadOnly] public ComponentDataFromEntity<Ground> GroundGroup;
    4.  
    5.   [WriteOnly] public EntityCommandBuffer CommandBuffer;
    6.  
    7.   public void Execute (CollisionEvent collisionEvent) {
    8.     Debug.Log("Execute!");
    9.     Entity entityA = collisionEvent.Entities.EntityA;
    10.     Entity entityB = collisionEvent.Entities.EntityB;
    11.  
    12.     bool isBodyAPlayer = JumpInputGroup.Exists(entityA);
    13.     bool isBodyBPlayer = JumpInputGroup.Exists(entityA);
    14.  
    15.     bool isBodyAGround = GroundGroup.Exists(entityA);
    16.     bool isBodyBGround = GroundGroup.Exists(entityB);
    17.  
    18.     if (isBodyAPlayer && isBodyBGround)
    19.       CommandBuffer.AddComponent<Jump>(entityA);
    20.  
    21.     if (isBodyAGround && isBodyBPlayer)
    22.       CommandBuffer.AddComponent<Jump>(entityB);
    23.   }
    24. }
    25.  
    26. protected override JobHandle OnUpdate (JobHandle inputDeps) {
    27.   var jobHandle = new StartJumpJob {
    28.     JumpInputGroup = GetComponentDataFromEntity<JumpInput>(true),
    29.     GroundGroup = GetComponentDataFromEntity<Ground>(true),
    30.     CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer(),
    31.   }.Schedule(m_StepPhysicsWorldSystem.Simulation,
    32.                 ref m_BuildPhysicsWorldSystem.PhysicsWorld, inputDeps);
    33.  
    34.   m_EntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);
    35.  
    36.   Debug.Log("before: " + jobHandle.IsCompleted);
    37.   jobHandle.Complete();
    38.   Debug.Log("after: " + jobHandle.IsCompleted);
    39.  
    40.   return inputDeps;
    41. }
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I assume that would just mean there are no collision events
     
  3. kstothert

    kstothert

    Joined:
    Dec 8, 2016
    Posts:
    68
    apparently that's not default behavior...thanks