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 Unity Physics interferes with basic movement job

Discussion in 'Physics for ECS' started by Hellothere_1, Aug 13, 2022.

  1. Hellothere_1

    Hellothere_1

    Joined:
    Sep 18, 2018
    Posts:
    32
    I'm super new to entities and just trying to figure stuff out right now.

    I'm working in 0.51.1 and one of the first things I did was make a very basic IJobEntity that moves an entity towards coordinates set in a Target component:

    Code (CSharp):
    1.     [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    2.     public partial class MoveToTarget : SystemBase
    3.     {
    4.         protected override void OnStartRunning()
    5.         {
    6.            
    7.         }
    8.  
    9.         protected override void OnUpdate()
    10.         {
    11.             new MoveToTargetJob { deltaTime = Time.DeltaTime }.Run();
    12.         }
    13.     }
    14.  
    15.     [BurstCompile]
    16.     public partial struct MoveToTargetJob : IJobEntity
    17.     {
    18.         public float deltaTime;
    19.         void Execute (ref Translation translation, in Target target)
    20.         {
    21.             if (!target.active || target.pos.Equals(translation.Value)) return;
    22.  
    23.             float3 dir = target.pos - translation.Value;
    24.             float3 maxMovement = math.normalize(dir) * deltaTime;
    25.             translation.Value += ClassExtensions.absMin(maxMovement, dir);
    26.         }
    27.     }
    As I said, super basic and it works fine.

    However, when I added the UnityPhysics package to my project it started generating a ton of errors:
    From what I understand the issue here is that I'm trying to write to the translation component while another job running at the same time is still accessing it. So far that makes sense to me.

    However, what I don't understand is why the physics system is accessing the translation component of an entity that has no collider or rigidbody or anything similar attached to it and should thus not need to interact with the physics system at all.

    As for fixing the issue, I tried some of the solutions I found in threads by people with similar issues (adding [UpdateAfter(typeof(ExportPhysicsWorld))],[UpdateBefore(typeof(ExportPhysicsWorld))], or putting this.RegisterPhysicsRuntimeSystemReadWrite() into OnStartRunning), to no effect.

    What do I need to do to fix this? Also, is there any kind of documentation on what jobs the Unity Physics scedules for entities and in what order so I can actually understand what is happening here?
     
  2. NT_Ninetails

    NT_Ninetails

    Joined:
    Jan 21, 2018
    Posts:
    195