Search Unity

ecb.AddSharedComponent incompatible with Burst?

Discussion in 'Burst' started by andywatts, Feb 12, 2022.

  1. andywatts

    andywatts

    Joined:
    Sep 19, 2015
    Posts:
    112
    Should ecb.AddSharedComponent work with Burst?

    Error

    /Library/PackageCache/com.unity.entities@0.17.0-preview.42/Unity.Entities/Types/FastEquality.cs(214,9): Burst error BC1051: Invalid managed type found for the field `EqualFn` of the struct `Unity.Entities.FastEquality.TypeInfo`.: the type `System.Delegate` is a managed type and is not supported



    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Entities.CodeGeneratedJobForEach;
    5. using Unity.Jobs;
    6. using Unity.Mathematics;
    7. using Unity.Transforms;
    8. using UnityEngine;
    9.  
    10. public struct MyShared : ISharedComponentData
    11. {
    12.     public bool Value;
    13. }
    14.  
    15. public class MySystem : SystemBase
    16. {
    17.     private EndSimulationEntityCommandBufferSystem ecbSystem;
    18.  
    19.     protected override void OnCreate()
    20.     {
    21.         ecbSystem = World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>();
    22.     }
    23.  
    24.     protected override void OnUpdate()
    25.     {
    26.         EntityCommandBuffer ecb = ecbSystem.CreateCommandBuffer();
    27.         Entities.ForEach((Entity e, int entityInQueryIndex, ref Translation translation, in Rotation rotation) =>
    28.         {
    29.             ecb.AddSharedComponent(e, new MyShared{Value = true});
    30.         })
    31.             //.WithoutBurst() // Works without burst
    32.             .Schedule();
    33.         ecbSystem.AddJobHandleForProducer(this.Dependency);
    34.     }
    35. }
     
  2. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    Reading, writing, and editing shared components are inherently not supported by Burst as they can include managed components.

    So yea, as intended, AddSharedComponent() will not work with Burst.

    Edit: As a side note, DOTS 0.50 might, keyword might, come with a blittable enforced shared component data compatible with burst and accessible inside a job. Would make my code a loooooot simpler so crossing my fingers and hoping.
     
    Last edited: Feb 14, 2022
    EirikWahl, andywatts and sheredom like this.