Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

InvalidOperationException: Code working in 2019.4, breaks in 2020.1.8f1?

Discussion in 'Physics for ECS' started by tonsillectomy, Oct 8, 2020.

  1. tonsillectomy

    tonsillectomy

    Joined:
    Jun 2, 2015
    Posts:
    18
    Hello,

    My old project is working fine in 2019.4, but when I updated it into 2020.1.8f1 the same code doesn't seem to work anymore.

    The issue seems to be with the execution order of my script. In 2019.4 I had fixed this problem with [UpdateBefore] and [UpdateAfter] attributes:

    Code (CSharp):
    1.  
    2. [UpdateAfter(typeof(BuildPhysicsWorld)), UpdateBefore(typeof(StepPhysicsWorld))]
    3. public class PlayerMovementSystem : SystemBase
    4. {
    5.     BuildPhysicsWorld _buildPhysicsWorldSystem;
    6.  
    7.     protected override void OnCreate()
    8.     {
    9.         _buildPhysicsWorldSystem = World.GetExistingSystem<BuildPhysicsWorld>();
    10.     }
    11.  
    12.     protected override void OnUpdate()
    13.     {
    14.         _buildPhysicsWorldSystem.GetOutputDependency().Complete();
    15.         var physicsWorld = _buildPhysicsWorldSystem.PhysicsWorld;
    16.         float dt = Time.DeltaTime;
    17.  
    18.         Entities.ForEach((Entity e, ref InputComponent input) =>
    19.         {
    20.             int rigID = physicsWorld.GetRigidBodyIndex(e);
    21.             float3 inputVector = new float3(input.x, 0f, input.y);
    22.             float3 velocity = physicsWorld.GetLinearVelocity(rigID);
    23.  
    24.             velocity.y = 0f;
    25.             float3 targetVelocity = inputVector * input.strength - velocity;
    26.  
    27.             physicsWorld.ApplyLinearImpulse(rigID, targetVelocity);
    28.  
    29.         }).Run();
    30.     }
    31. }

    After updating to 2020.1.8f I get the following errors:


    Ignoring invalid [UpdateBefore] attribute on PlayerMovementSystem targeting Unity.Physics.Systems.StepPhysicsWorld.
    This attribute can only order systems that are members of the same ComponentSystemGroup instance.
    Make sure that both systems are in the same system group with [UpdateInGroup(typeof(Unity.Entities.SimulationSystemGroup)],
    or by manually adding both systems to the same group's update list.


    The same with [UpdateAfter] and then:

    InvalidOperationException: The previously scheduled job Integrator:ParallelIntegrateMotionsJob writes to the
    Unity.Collections.NativeArray`1[Unity.Physics.MotionVelocity] ParallelIntegrateMotionsJob.MotionVelocities.
    You must call JobHandle.Complete() on the job Integrator:ParallelIntegrateMotionsJob,
    before you can read from the Unity.Collections.NativeArray`1[Unity.Physics.MotionVelocity] safely.



    Any ideas how to fix this?

    Thanks!
     
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    If you want to link your system to physics system, they need to be in the same group. Add [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))] to your PlayerMovementSystem.

    Physics systems have moved to this group in the latest update.
     
    tonsillectomy likes this.
  3. tonsillectomy

    tonsillectomy

    Joined:
    Jun 2, 2015
    Posts:
    18
    Ah, thank you!! <3
     
    petarmHavok likes this.
  4. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    My pleasure!