Search Unity

begginner's questions about c# job system

Discussion in 'C# Job System' started by Danistmein, Jan 23, 2019.

  1. Danistmein

    Danistmein

    Joined:
    Nov 15, 2018
    Posts:
    82
    Hello, everybody.

    I'm wondering about when the OnUpdate() function is called. In the tutorial, the speacker said that when the conditions these conditions is filled, like the follow sample:
    Code (CSharp):
    1. public class MovementSystem : JobComponentSystem{
    2.     [ComputeJobOptimization]
    3.     struct MovementJob : IJobProcessComponentData<Position, Rotation, MoveSpeed>
    4.     {
    5.         public float zStart;
    6.         public float zEnd;
    7.         public float deltaTime;
    8.         public void Execute(ref Position inPosition, ref Rotation inRotation, ref MoveSpeed inSpeed)
    9.         {
    10.           // do something....
    11.         }
    12.     }
    13.  
    14.     protected override JobHandle OnUpdate(JobHandle inDeps)
    15.     {
    16.         // do something...
    17.     }
    18. }

    But, in othercases, there is not only one job in a system. In that case, do I need to fill the all jobs conditions in a system?
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    JobComponentSystem will automatically create a ComponentGroup for each IJobProcessComponentData for you.

    The system will be executed, if there is at least one ComponentGroup which can be processed (not empty).
    A JobComponentSystem just schedules the jobs.
    The Job it self will be executed depending on it's dependencies (JobHandle + Read/Write access of Components) or the Complete instruction.

    By default OnUpdate will be called in the Update loop of the game. You can use UpdateBefore/ UpdateAfter attributes to
    controll the execution order and the loop. (If you want to execute a system in FixedUpdate or LateUpdate)
     
    Antypodish likes this.
  3. Danistmein

    Danistmein

    Joined:
    Nov 15, 2018
    Posts:
    82
    Thank you for the answer!