Search Unity

[Help] Burst error on a system that works fine without burst.

Discussion in 'Burst' started by georgeq, Mar 6, 2020.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    This system moves a set of blocks 1 row down on every frame for certain amount of frames. Another system evaluates all the blocks in the scene and if any of them needs to be moved, it attaches a BlockDrop component to it, indicating the number of rows it needs to move. Once the block reaches its position, the BlockDrop component most be removed in order for it to stop moving.

    Here is the code:

    Code (CSharp):
    1. public class BlockDropSystem : JobComponentSystem {
    2.  
    3.       BeginInitializationEntityCommandBufferSystem BufferSystem;
    4.  
    5.       protected override void OnCreate() {
    6.          BufferSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
    7.       }
    8.  
    9.       [BurstCompile]
    10.       struct DropJob : IJobForEachWithEntity<Translation,BlockDrop> {
    11.  
    12.          public EntityCommandBuffer.Concurrent Buffer;
    13.  
    14.          public void Execute(Entity entity,int index,ref Translation translation,ref BlockDrop drop) {
    15.  
    16.             translation.Value.y--;
    17.             drop.Rows--;
    18.             if(drop.Rows<=0) {
    19.                Buffer.RemoveComponent(index,entity,typeof(BlockDrop));
    20.             }
    21.  
    22.          }
    23.  
    24.       }
    25.  
    26.       protected override JobHandle OnUpdate(JobHandle jobDeps) {
    27.  
    28.          DropJob job = new DropJob() {
    29.             Buffer = BufferSystem.CreateCommandBuffer().ToConcurrent()
    30.          };
    31.          return job.Schedule(this,jobDeps);
    32.  
    33.       }
    34.  
    35.    }
    The system works fine, but when I enable Burst compilation, I get an error telling me: Accessing the type `BlockDrop` is not supported at line 19. Which is the one that removes the BlockDrop component.

    Any idea about why I'm not allowed to remove this component under Burst?
     
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    Does using the generic version
    Buffer.RemoveComponent<BlockDrop>(index, entity);
    fix the issue? Never tried using
    typeof
    inside a Job as the result is a System.Type (which is a managed type).
     
    Ksanone and vectorized-runner like this.
  3. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Yes! Thank you!
     
    brunocoimbra likes this.