Search Unity

Readonly attribute on a component for a job system causing freezing editor in play-mode.

Discussion in 'C# Job System' started by FixItFelix, Jun 4, 2019.

  1. FixItFelix

    FixItFelix

    Joined:
    Mar 27, 2017
    Posts:
    54
    Hello,

    I have written this system and experience a weird behavior. Before I missed the [ReadOnly] attribute on the NavMeshAgentGetter. Everything ran fine. Now I added the [ReadOnly] attribute as you can see below. But whenever this system starts to run (a destination exists) the editor freezes totally forever.

    The reason is the read-only attribute but it makes total sense to have that. Has anybody an idea what the freeze could cause?

    Code (CSharp):
    1. public class NavMeshAgentVelocityToAnimationSystem : JobComponentSystem {
    2.  
    3.         [RequireComponentTag(typeof(Destination))] // only run if entity has a destination
    4.         [BurstCompile]
    5.         private struct SetVelocityJob :IJobForEach_BC<AnimatorKeyValueIntFloatBufferElement, NavMeshAgentGetter> {
    6.  
    7.             public int AnimatorIdMovementSpeed;
    8.  
    9.             public void Execute(DynamicBuffer<AnimatorKeyValueIntFloatBufferElement> buffer, [ReadOnly] ref NavMeshAgentGetter navMeshAgentGetter) {
    10.                 buffer.Add(new AnimatorKeyValueIntFloatBufferElement {
    11.                     Key = AnimatorIdMovementSpeed,
    12.                     Value = math.max(0.1f, math.length(navMeshAgentGetter.Velocity))
    13.                 });
    14.             }
    15.         }
    16.        
    17.         protected override JobHandle OnUpdate(JobHandle inputDeps) {
    18.  
    19.             var job = new SetVelocityJob
    20.             {
    21.                 AnimatorIdMovementSpeed = AnimatorIds.MovementSpeed
    22.             };
    23.             return job.ScheduleSingle(this, inputDeps);
    24.         }
    25.     }