Search Unity

Cannot update object rotation

Discussion in 'Entity Component System' started by trojanfoe_, Mar 16, 2019.

  1. trojanfoe_

    trojanfoe_

    Joined:
    May 20, 2014
    Posts:
    53
    I am just starting with ECS and I am playing with a simple test component that rotates an object around a central point. The object translation is being updated successfully, however I cannot get it to rotate to face the central position. I know the maths probably isn't correct, however I would expect the rotation to change, which it isn't. Can anyone help?

    Code (CSharp):
    1. public class RotateAroundPointSystem : JobComponentSystem
    2. {
    3.     [BurstCompile]
    4.     struct RotateAroundPointJob : IJobProcessComponentData<Translation, Rotation, RotateAroundPoint>
    5.     {
    6.         public float DeltaTime;
    7.  
    8.         public void Execute(ref Translation translation, ref Rotation rotation, ref RotateAroundPoint rotateAroundPoint)
    9.         {
    10.             var cosine = math.cos(rotateAroundPoint.AngleRad) * rotateAroundPoint.Distance;
    11.             var sine = math.sin(rotateAroundPoint.AngleRad) * rotateAroundPoint.Distance;
    12.  
    13.             var position = translation.Value;
    14.             position.x = rotateAroundPoint.Centre.x + cosine - sine;
    15.             position.z = rotateAroundPoint.Centre.z + sine + cosine;
    16.             translation.Value = position;
    17.  
    18.             //var angleBetween = MathUtils.Angle(position, rotateAroundPoint.Centre);
    19.             //rotation.Value = quaternion.AxisAngle(math.up(), math.degrees(rotateAroundPoint.AngleRad));
    20.  
    21.             rotation.Value = quaternion.RotateY(math.degrees(rotateAroundPoint.AngleRad));
    22.  
    23.             rotateAroundPoint.AngleRad += DeltaTime * rotateAroundPoint.Speed;
    24.         }
    25.     }
    26.  
    27.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    28.     {
    29.         var job = new RotateAroundPointJob {
    30.             DeltaTime = Time.deltaTime
    31.         };
    32.  
    33.         return job.Schedule(this, inputDeps);
    34.     }
    35. }
     
  2. trojanfoe_

    trojanfoe_

    Joined:
    May 20, 2014
    Posts:
    53
    OK so while I'm trying to track this down I have been commenting-out areas of code and the object is still rotating around the central point (even putting return at the start of the Execute() method). What is going on? There are literally 3 source files in the project (the component, the proxy and the system) and it still seems to be using old code?
     
  3. trojanfoe_

    trojanfoe_

    Joined:
    May 20, 2014
    Posts:
    53
    So closing the project, deleting the temp directories and re-opening the project is now loading the new system code and the object is no longer working, so it appears new code is being ignored? That seems bad.

    Edit: Removing the [BurstCompile] attribute now causes the code to reload.
     
  4. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    I just had the same problem.. Couldn't wrap my head around why my code edits weren't doing anything.. tried recompile in editor, removing the Burst attribute etc.. only thing that made the editor properly reload and compile we shutting down and re-opening.
    .
    Using preview 29, burst 1.0-preview4 etc. and currently been using Rider 2018.3.4

    Edit: Same issue with Visual Studio.
    Edit 2: Yes turning off BurstCompile bypasses the problem.
     
    Last edited: Mar 16, 2019
    trojanfoe_ likes this.
  5. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Here is the really weird thing! Once I hit play the new code is there for a few frames and then it looks like it hot-reloads an old version and snaps back.
     
  6. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    Ok you can downgrade to Burst 0.2.4-preview50 as a workaround until a fix is released.
     
  7. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    418
    Our apologize for this regression. We have fixed it and a new version of burst 1.0.0-preview.5 is being prepared and will be pushed soon (at least to the staging registry, it will be available to the public registry tomorrow)
     
  8. siggigg

    siggigg

    Joined:
    Apr 11, 2018
    Posts:
    247
    New version is out, and I can confirm it fixes the issue for me. Thanks!
     
  9. trojanfoe_

    trojanfoe_

    Joined:
    May 20, 2014
    Posts:
    53
    Thanks guys it's all working again!
     
    siggigg likes this.