Search Unity

Self-contained/repeatable rotation

Discussion in 'Entity Component System' started by shadowlord1, Feb 16, 2019.

  1. shadowlord1

    shadowlord1

    Joined:
    Aug 15, 2014
    Posts:
    32
    Hello everyone! I'm studying ECS and the Job System...

    I've a 3D plane in my scene and I want it to rotate around its Y axis. (At the moment, I'm not using ECS)
    So far I've the following:
    Code (CSharp):
    1. public struct rotateJob : IJobParallelForTransform
    2.     {
    3.         public float rotationSpeed;
    4.         public float deltaTime;
    5.         public void Execute(int index, TransformAccess transform)
    6.         {        
    7.             transform.localRotation *= Quaternion.Euler(new Vector3(0,rotationSpeed * deltaTime, 0));
    8.         }
    9.     }
    Inside the Update(), I schedule it and then call JobHandle.ScheduleBatchedJobs();

    My questions are:
    1. Is there a way to keep repeating (re-calling) this job indefinitely without using the Update() from Main thread? Something like a recursive function.
    2. I've just one object, do I need to use IJobParallelForTransform to be able to use
      TransformAccess?
    3. If we need to call a job from inside Update() doesn't it forces the main thread to wait for the job to complete? Is it possible to make it really parallel?
    4. Is there a more efficient way to keep this gameObject rotating?

    Thank you in advance!
     
    Last edited: Feb 16, 2019
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    Alternative way, is simply update Rotation component.
    You can pass it to any job and as well burst.

    Typically you use, updates on main thread, jus to schedule the jobs.
     
  3. shadowlord1

    shadowlord1

    Joined:
    Aug 15, 2014
    Posts:
    32
    Thank you very much!

    On the case of having this endless rotation (I want it to stop just when I call a method to, otherwise, it should kept rotating "forever")... Do I need to keep instantiating the job and scheduling it on the Update of the main thread?
    Is there a way to schedule 1 job and it keeps executing the rotation until I order it to stop?

    Because so far, it seems to me that I need to run one job to each increment of this rotation.... Supposing one job rotate the object 1º... I've to run 360x the job instantiating on the update to make it rotates 360º. It doesn't feel right to me.
    Is it?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    You can add / remove rotation component at will, to trigger rotation system.
    Or have system, which sets delta rotation to 0, or to desired value. Then you don't need add / remove components. And relevant system will keep doing actual rotation.

    Just some options. But not only.