Search Unity

[GenerateAuthoringComponent]+unsafe codegen 0.50

Discussion in 'Entity Component System' started by JooleanLogic, Apr 30, 2022.

  1. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    [GenerateAuthoringComponent] code-gen doesn't seem to cater for unsafe code.
    Is there a setting somewhere for this? I couldn't find anything in the upgrade guide.

    Component
    Code (CSharp):
    1. [GenerateAuthoringComponent]
    2. public unsafe struct BuffComp : IComponentData
    3. {
    4.     public fixed float value[4];
    5. }
    Generated Component
    Code (CSharp):
    1. public class BuffCompAuthoring : UnityEngine.MonoBehaviour, Unity.Entities.IConvertGameObjectToEntity
    2. {
    3.     [Unity.Entities.RegisterBinding(typeof(BuffComp), "value")]
    4.     public float *value;
    5.     public void Convert(Unity.Entities.Entity __entity, Unity.Entities.EntityManager __dstManager, GameObjectConversionSystem __conversionSystem)
    6.     {
    7.         BuffComp component = default(BuffComp);
    8.         component.value = value;
    9.         __dstManager.AddComponentData(__entity, component);
    10.     }
    11. }
    Error
    Code (CSharp):
    1. Temp/GeneratedCode/Assembly-CSharp/BuffComp__AuthoringComponent_837250236.g.cs(4,12): error CS0214: Pointers and fixed size buffers may only be used in an unsafe context