Search Unity

Bug Havok: StepJob

Discussion in 'Physics for ECS' started by argibaltzi, Jan 11, 2023.

  1. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Since upgrading to 1.0 i am having trouble with Havok, it causes constant lag spikes even on empty worlds.

    Unity Physics runs fine, is there anything that i am missing?
    my other systems it seems to hang on are not doing anything

    Just this (but there are no entities to run it on)
    Entities.WithoutBurst().ForEach((Entity entity, ref ECSCollisionComponentData collision, in PhysicsVelocity velocity, in LocalTransform translation) =>

    Thanks!
     
    Last edited: Jan 11, 2023
  2. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Can someone please explain why havok does not work properly in 1.0? Even in the main menu scene with nothing on it drags the framerate down to 2fps
     
  3. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    Hi @argibaltzi ! Thanks for reporting this issue.
    Could you try the same again after removing the "WithoutBurst()" function call, please?
     
  4. yifanchu183

    yifanchu183

    Joined:
    Jul 4, 2019
    Posts:
    41
    upload_2023-1-18_21-22-4.png
    same StepJob take too much time, make my project feel stuck once in a while
     
  5. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    Yeah that is definitely unusual.
    Would you mind providing us with your project so that we can reproduce this? I assume it's not just a default, empty project but you have some systems in there that might be running here which could somehow be related to this slowdown.
    I tried reproducing in an empty project and the issue you are describing did not reproduce.
     
    JMPM-UNITY likes this.
  6. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Havok seems to have problem with every system i have in the physics groups, even if they are bursted. I commend out 1 system as a test and it then it finds another one to hang one.

    Code (CSharp):
    1. [RequireMatchingQueriesForUpdate]
    2. [UpdateInGroup(typeof(BeforePhysicsSystemGroup))]
    3. [UpdateAfter(typeof(ConvertWheelJointsSystem))]
    4. [UpdateBefore(typeof(BuildPhysicsWorld))]
    5. public partial class WheelMotorSystem : SystemBase
    6. {
    7.     protected override void OnUpdate()
    8.     {
    9.         FixedStepSimulationSystemGroup FixedStepSimulation = World.GetExistingSystemManaged<FixedStepSimulationSystemGroup>();
    10.  
    11.         float delta = FixedStepSimulation.Timestep;
    12.  
    13.         EntityCommandBuffer frameCmd = new EntityCommandBuffer(Allocator.Temp, PlaybackPolicy.SinglePlayback);
    14.  
    15.  
    16.         Entities.WithBurst().ForEach((ref ECSWheelMotorComponentData convertJoint, ref PhysicsVelocity velocity, in PhysicsMass mass, in Entity entity) =>
    17.         {
    18.             velocity.ApplyAngularImpulse(in mass, convertJoint.TorquePerSecond);
    19.  
    20.             velocity.Linear += new float3(0, convertJoint.DownwardForce * delta, 0);
    21.  
    22.             //velocity.Angular += convertJoint.TorquePerSecond * delta;
    23.  
    24.  
    25.         }).Run();
    26.  
    27.         frameCmd.Playback(World.EntityManager);
    28.         frameCmd.Dispose();
    29.     }
    30. }
    It now hangs on this tiny system which is also bursted
     
    Last edited: Jan 21, 2023
  7. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    https://we.tl/t-0sW0VXmpVO
    This is a simple project where HAVOK constantly spikes in the profiler, its almost as if by design.......
    Unity 2022.2.0

    I even saw a job in the presentation system waiting for havok
     
    msimic_Havok and daniel-holz like this.
  8. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    Thanks! We will have a look and get back to you.
     
  9. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    We are able to reproduce the issue on our end and are looking into it at the moment. Stay tuned!
    upload_2023-1-27_1-16-50.png
     
    Kmsxkuse likes this.
  10. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    While we are investigating the issue, feel free to disable multi threading in the Physics Step component, which eliminates the staggering.
    upload_2023-1-27_1-20-47.png
     
    Kmsxkuse and msimic_Havok like this.
  11. Sima_Havok

    Sima_Havok

    Joined:
    Dec 16, 2019
    Posts:
    52
    I have managed to repro the issue and number of threads is causing it.

    The easiest way to workaround the issue is to set JobsUtility.JobWorkerCount to smaller value than default (number of logical cores - 1).

    So in the attached repro it is enough to add code below into DotsTest1System class.
    Code (CSharp):
    1. protected override void OnCreate()
    2. {
    3.     Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 7;
    4. }
    This will limit number of job worker threads on the app level. Reducing the number of job worker threads just for Havok requires editing Havok Physics package which is more cumbersome process.
     
    daniel-holz likes this.
  12. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Ok gyes thank you, will try the fix and keep you posted. I used havok extensively in the 0.50 era and never had a problem with it.
     
    daniel-holz likes this.
  13. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = 7;
    works on my computer but what about other computers? whats the best way to write this? and obviously this is not an ideal solution..... neither is disabling multithreading

    I have 6 cores and 12 threads
    my default JobsUtility.JobWorkerCount was 11

    When can we expect a proper fix in the package?
     
    Last edited: Jan 29, 2023
  14. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    @argibaltzi: We totally agree that this is not ideal. This suggestion serves just as a temporary workaround to unblock you immediately. We have filed a ticket for this issue internally and are working on a solution.

    Once we have a better understanding of the timeline for the fix, we will report back to you. Stay tuned!
     
    argibaltzi and Occuros like this.
  15. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278
    @argibaltzi : Good news! We have made a fix for this issue which will be added to the next pre-release of 1.0.
     
    argibaltzi likes this.
  16. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    any rough estimate when would that be? :)
     
  17. daniel-holz

    daniel-holz

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    278