Search Unity

[Solved] Job dependency error error CS1503

Discussion in 'Entity Component System' started by RBogdy, May 28, 2019.

  1. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Hello,

    I'm trying to replicate the MousePickBehaviour from UnityPhysicsExamples however when I try to combine the dependencies for BuildPhysicsWorldSystem.FinalJobHandle and my RayCasting Job, I get the following error:

    error CS1503: Argument 2: cannot convert from 'Unity.Jobs.JobHandle' to 'Unity.Entities.EntityQuery'

    The only difference between the repository project and mine is that the repo uses an IJob for getting the RayCast results (and then stores them in a NativeArray) and I am using an IJobForEach<> because I want the results stored in a component I created.

    Is IJobForEach unable to combine dependencies or is there something that I'm missing?
     
  2. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    The error shows for the line above inputPhaseTrackerJobHandle = handle;
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    can you post a code snippet, looks like a type error
     
  4. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Code (CSharp):
    1. using System;
    2. using Unity.Burst;
    3. using Unity.Collections;
    4. using Unity.Entities;
    5. using Unity.Jobs;
    6. using Unity.Mathematics;
    7. using Unity.Physics;
    8. using Unity.Physics.Systems;
    9. using Unity.Transforms;
    10. using UnityEngine;
    11. using static Unity.Mathematics.math;
    12. using static Unity.Physics.Math;
    13.  
    14. [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateBefore(typeof(EndFramePhysicsSystem))]
    15. public class InputPhaseTracker : JobComponentSystem
    16. {
    17.     BuildPhysicsWorld m_BuildPhysicsWorldSystem;
    18.  
    19.     public float3 mouseStartPos;
    20.     public float3 mouseEndPos;
    21.     public bool dragStart;
    22.     public bool dragEnd;
    23.     public Unity.Physics.Ray rayForJob;
    24.  
    25.     public JobHandle? inputPhaseTrackerJobHandle;  
    26.  
    27.     [BurstCompile]
    28.     struct InputPhaseTrackerJob : IJobForEach<PlayerInput>
    29.     {
    30.         [ReadOnly] public CollisionWorld CollisionWorld;
    31.         [ReadOnly] public int NumDynamicBodies;
    32.                
    33.         public float3 mousePosStart;
    34.         public float3 mousePosEnd;
    35.         public bool draggingStart;
    36.         public bool draggingFinish;
    37.         public Unity.Physics.Ray Ray;
    38.  
    39.         public void Execute([WriteOnly] ref PlayerInput playerInput)
    40.         {
    41.             float fraction = 1.0f;
    42.             RigidBody? hitBody = null;
    43.             var rayCastInput = new RaycastInput { Ray = Ray, Filter = CollisionFilter.Default };
    44.  
    45.             if (CollisionWorld.CastRay(rayCastInput, out Unity.Physics.RaycastHit hit))
    46.             {
    47.                 if (hit.RigidBodyIndex < NumDynamicBodies)
    48.                 {
    49.                     hitBody = CollisionWorld.Bodies[hit.RigidBodyIndex];
    50.                     fraction = hit.Fraction;
    51.                 }
    52.             }
    53.  
    54.             if (hitBody != null)
    55.             {
    56.                 float3 pointInWorld = (Ray.Origin + Ray.Direction * fraction);
    57.                 MTransform bodyFromWorld = Inverse(new MTransform(hitBody.Value.WorldFromBody));
    58.                 float3 pointOnBody = Mul(bodyFromWorld, pointInWorld);
    59.                 playerInput.Entity = hitBody.Value.Entity;
    60.                 playerInput.PointOnBody = pointOnBody;
    61.                 playerInput.DragStart = draggingStart;
    62.                 playerInput.MousePosStart = mousePosStart;
    63.                 playerInput.MousePosEnd = mousePosEnd;
    64.                 playerInput.DragFinish = draggingFinish;
    65.             }
    66.         }
    67.     }
    68.  
    69.     protected override void OnCreate()
    70.     {
    71.         m_BuildPhysicsWorldSystem = World.GetOrCreateSystem<BuildPhysicsWorld>();
    72.     }
    73.  
    74.     protected override JobHandle OnUpdate(JobHandle inputDependencies)
    75.     {
    76.         var handle = JobHandle.CombineDependencies(inputDependencies, m_BuildPhysicsWorldSystem.FinalJobHandle);
    77.  
    78.         if (Input.GetMouseButtonDown(0) && (Camera.main != null))
    79.         {
    80.             mouseStartPos = Input.mousePosition;
    81.             UnityEngine.Ray unityRay = Camera.main.ScreenPointToRay(mouseStartPos);
    82.             rayForJob = new Unity.Physics.Ray(unityRay.origin, unityRay.direction * 15.0f);
    83.             dragStart = true;
    84.             dragEnd = false;          
    85.         }
    86.  
    87.         if (Input.GetMouseButtonUp(0))
    88.         {
    89.             mouseEndPos = Input.mousePosition;
    90.             dragEnd = true;
    91.             dragStart = false;          
    92.         }
    93.  
    94.         handle = new InputPhaseTrackerJob
    95.         {
    96.             CollisionWorld = m_BuildPhysicsWorldSystem.PhysicsWorld.CollisionWorld,
    97.             NumDynamicBodies = m_BuildPhysicsWorldSystem.PhysicsWorld.NumDynamicBodies,
    98.             mousePosStart = mouseStartPos,          
    99.             mousePosEnd = mouseEndPos,
    100.             draggingStart = dragStart,
    101.             draggingFinish = dragEnd,
    102.             Ray = rayForJob,
    103.         }.Schedule(JobHandle.CombineDependencies(handle, m_BuildPhysicsWorldSystem.FinalJobHandle));
    104.  
    105.         inputPhaseTrackerJobHandle = handle;
    106.  
    107.         handle.Complete();
    108.  
    109.         return handle;
    110.     }
    111. }
     
  5. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    I fixed it by changing the way the OnUpdate() method is ran, removing the initial var handle and assigning var handle directly to new InputPhaseTrackerJob()
     
    Last edited: May 29, 2019