Search Unity

Editor loop idle for 30ms in profiler?

Discussion in 'Entity Component System' started by MintTree117, Apr 1, 2020.

  1. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340
    For some reason my game slows down like this when I schedule this job.
    Code (CSharp):
    1.     [BurstCompile] private struct MovementJob : IJobForEachWithEntity<PathIndex , PlatoonReference , Translation>
    2.     {
    3.         [ReadOnly] public float dt;
    4.         [ReadOnly] public BufferFromEntity<PathPosition> pathPositionBufferFromEntity;
    5.  
    6.         public void Execute( Entity entity , int index , ref PathIndex pathIndex , ref PlatoonReference reference , ref Translation translation )
    7.         {
    8.             if ( pathIndex.value >= 0 )
    9.             {
    10.                 DynamicBuffer<PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[ reference.entity ];
    11.  
    12.                 float3 pathPosition = new float3(
    13.                     pathPositionBuffer[ pathIndex.value ].position.x ,
    14.                     translation.Value.y ,
    15.                     pathPositionBuffer[ pathIndex.value ].position.y );
    16.                 float distance = math.distance(
    17.                     pathPosition , translation.Value );
    18.                 float3 direction = math.normalize(
    19.                     pathPosition - translation.Value );
    20.  
    21.                 int branch = math.select( 0 , 1 , math.abs( direction.x ) <= 1 );
    22.                 float3 value = new float3(
    23.                     direction.x * 30f * dt ,
    24.                     0 ,
    25.                     direction.z * 30f * dt );
    26.  
    27.                 translation.Value += value * branch;
    28.  
    29.                 branch = math.select( 0 , 1 , distance <= 0.3f );
    30.                 pathIndex.value -= branch;
    31.             }
    32.         }
    33.     }
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
  3. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340