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.
  2. Dismiss Notice

Question Trying to understand a job error

Discussion in 'Entity Component System' started by Ofx360, Oct 12, 2022.

  1. Ofx360

    Ofx360

    Joined:
    Apr 30, 2013
    Posts:
    155
    So i setup this fairly simply script to try out IJobEntity (instead of the simpler foreach loop). After using ScheduleParallel() like in the docs, i decided to try Run() but started getting spammed with errors that i'm missing something even though this is the only system i have operating over this entity:
    Here's the code:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3. using Unity.Transforms;
    4. using Unity.Collections;
    5. using Unity.Burst;
    6.  
    7. public partial struct SateliteSystem : ISystem
    8. {
    9.     EntityQuery query;
    10.  
    11.     public void OnCreate(ref SystemState state)
    12.     {
    13.         var builder = new EntityQueryBuilder(Allocator.Temp);
    14.         builder.WithAll<SateliteComponent>();
    15.         builder.WithAllRW<Translation>();
    16.         builder.WithAllRW<Rotation>();
    17.         query = builder.Build(ref state);
    18.     }
    19.  
    20.     public void OnDestroy(ref SystemState state)
    21.     {
    22.     }
    23.  
    24.     public void OnUpdate(ref SystemState state)
    25.     {
    26.         var dt = SystemAPI.Time.DeltaTime;
    27.  
    28.         new TestJob{ deltaTime = dt }.Run(query);
    29.     }
    30. }
    31.  
    32. [BurstCompile]
    33. public partial struct TestJob : IJobEntity
    34. {
    35.     public float deltaTime;
    36.  
    37.     void Execute(ref Translation transform)
    38.     {
    39.         transform.Value += new float3(0, 1 * deltaTime, 0);
    40.     }
    41. }
    Here's the full error:
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    You have to call
    state.CompleteDependency();
    before running a job in a struct implementing ISystem
     
  3. Ofx360

    Ofx360

    Joined:
    Apr 30, 2013
    Posts:
    155
    Great, that does stop the errors!

    And I'm guessing this is just for when i'm using Run(), not when i'm using the various Schedule...() methods?

    Not seeing much info on this (or ISystem) on the docs