Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Prevent Job Execution / Iteration

Discussion in 'Entity Component System' started by dCalle, May 13, 2020.

  1. dCalle

    dCalle

    Joined:
    Dec 16, 2013
    Posts:
    55
    Hey guys!

    So this time, it would be nice if I could prevent the execution of a job or to stop the current iteration.

    how do I achieve that?


    Code (CSharp):
    1.         var arrayHandle = Job.WithCode(() =>
    2.         {
    3.             array = queue.ToArray(Allocator.TempJob);
    4.             if (array.Length == 0)
    5.             {
    6.                 // prevent next Job here
    7.             }
    8.         }).Schedule(queueHandle);
    9.  
    10.         Entities.ForEach((in Entity entity, in UnassignedGravity gravity, in Translation translation) =>
    11.         {
    12.             if (array.Length == 0)
    13.             {
    14.                 //end iteration here
    15.             }
    16.         // rest of code
    17.         }).ScheduleParallel(arrayHandle);
    18.  
     
  2. LazyGameDevZA

    LazyGameDevZA

    Joined:
    Nov 10, 2016
    Posts:
    143
    @dCalle this should do the trick.

    Code (CSharp):
    1.         var arrayHandle = Job.WithCode(() =>
    2.         {
    3.             array = queue.ToArray(Allocator.TempJob);
    4.             if (array.Length == 0)
    5.             {
    6.                 return;
    7.             }
    8.         }).Schedule(queueHandle);
    9.         Entities.ForEach((in Entity entity, in UnassignedGravity gravity, in Translation translation) =>
    10.         {
    11.             if (array.Length == 0)
    12.             {
    13.                 return;
    14.             }
    15.         // rest of code
    16.         }).ScheduleParallel(arrayHandle);
    17.  
     
    dCalle likes this.
  3. dCalle

    dCalle

    Joined:
    Dec 16, 2013
    Posts:
    55
    thanks man, I just figured, I can simply use an if statement before the second foreach. (Of course I have to use Run()) and if I use its handle just check if its null... Weird stuff, not the best one could wish for... but obviously, I dabble^^
     
    Last edited: May 14, 2020