Search Unity

How to properly start multiple jobs (in parallel) from the JobComponentSystem?

Discussion in 'Entity Component System' started by xVergilx, Aug 5, 2019.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I can't seems to figure this one out.
    E.g. I've tried this:
    Code (CSharp):
    1.         protected override JobHandle OnUpdate(JobHandle inputDeps) {
    2.             ...
    3.  
    4.             using (var handles = new NativeList<JobHandle>(Allocator.TempJob)) {
    5.                 // handles.Add(inputDeps); also tried with this one and w/o
    6.                 if (_setDir) {
    7.                     handles.Add(new ApplyDirJob(new float3(_normalizedEdgeDir.x,
    8.                                                            0,
    9.                                                            _normalizedEdgeDir.y)).Schedule(this, inputDeps));
    10.                 }
    11.  
    12.                 if (_sendMovementOrder) {
    13.                     handles.Add(new SetupMovementOrderJob {
    14.                                                               Destination = _movementOrderDest
    15.                                                           }.Schedule(_selectDestHasMoveQuery, inputDeps));
    16.                     _sendMovementOrder = false;
    17.                 }
    18.  
    19.                 return JobHandle.CombineDependencies(handles.AsArray());
    20.             }
    21.         }
    But sometimes, when _sendMovementOrder becomes true, I get:
    This happens when I select the entity in the debugger with that movement order attached.

    Is this a quirk of entity debugger, or I'm doing it incorrectly?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Are you using latest version of Entities?
    And are you able to show your jobs? (really just need to know the interface)
    What queries show up in the entity debugger? In particular what it is _selectDestHasMoveQuery but what other queries exist? Are you using any queries with Exclude?

    I don't think it has anything to do with CombineDependencies. I have a couple of suspicions what could be issue be (they are all known bugs) but need more info on to determine which one it is.
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    I'm using latest afaik ("com.unity.entities": "0.1.0-preview").

    Query is defined like so:
    Code (CSharp):
    1.  var selectDestNoMove = new EntityQueryDesc {
    2.                                            All = new[] {
    3.                                                           ComponentType.ReadOnly<Selected>(),
    4.                                                           ComponentType.ReadOnly<RVOAgentState>()
    5.                                                        },
    6.                                           None = new[] {
    7.                                                             ComponentType.ReadOnly<MovementOrder>()
    8.                                                        }
    9. };
    So it may count as having .Exclude?

    Job is defined like this:
    Code (CSharp):
    1. [BurstCompile]
    2. private struct SetupMovementOrderJob : IJobForEach<MovementOrder> {
    3.       public float3 Destination;
    4.  
    5.       public void Execute(ref MovementOrder order) {
    6.           order.Destination = Destination;
    7.       }
    8. }
    Can't look at debugger right now (busy on different project), but will check it later.

    Edit:
    I'm suspecting that this could be a bug, because it seems to happen only when entity is selected & visible in the inspector via entity debugger.

    Although I'm not sure whats triggering it.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    What was the signature of the ApplyDirJob out of interest? Out of curiously, if you pass it a direct query (instead of this) does the issue persist? Just wondering if it has anything to do with the wrong query matching bug (that I'm not sure if it was fixed or not).