How to Set MaterialPropertyAuthoring for float[] ?

I know how to set MaterialPropertyAuthoring for single type property ,just like below:

using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;

[MaterialProperty("_Length")]
public struct CustomMaterialPropertyLength : IComponentData
{
    public float LengthValue;
}

[UnityEngine.DisallowMultipleComponent]
public class CustomMaterialPropertyLengthAuthoring : UnityEngine.MonoBehaviour
{
    [Unity.Entities.RegisterBinding(typeof(CustomMaterialPropertyLength), nameof(CustomMaterialPropertyLength.LengthValue))]
    public float Length=5;

    class CustomMaterialPropertyLengthBaker : Unity.Entities.Baker<CustomMaterialPropertyLengthAuthoring>
    {
        public override void Bake(CustomMaterialPropertyLengthAuthoring authoring)
        {
            CustomMaterialPropertyLength component = default(CustomMaterialPropertyLength);
            component.LengthValue = authoring.Length;
            var entity = GetEntity(TransformUsageFlags.Renderable);
            AddComponent(entity, component);
        }
    }
}

But, when it turns to be float[ ] , it can’t work anymore,because it is managed type;

[MaterialProperty("_LengthArray")]
public struct MaterialPropertyLengthArray : IComponentData
{
    public float[] LengthArray;
}

Then, I tried to change it into NativeArray

[MaterialProperty("_LengthArray")]
public struct MaterialPropertyLengthArray : IComponentData
{
    public NativeArray<float> LengthArray;
}

[UnityEngine.DisallowMultipleComponent]
public class MaterialPropertyLengthArrayAuthoring : UnityEngine.MonoBehaviour
{
    [Unity.Entities.RegisterBinding(typeof(MaterialPropertyLengthArray), nameof(MaterialPropertyLengthArray.LengthArray))]
    public float[] LengthArray = new float[]{1,1,1,1,1,1,1,1};

    class MaterialPropertyLengthArrayBaker : Unity.Entities.Baker<MaterialPropertyLengthArrayAuthoring>
    {
        public override void Bake(MaterialPropertyLengthArrayAuthoring authoring)
        {
             MaterialPropertyLengthArray component;
             component.LengthArray = new NativeArray<float>(authoring.LengthArray,Allocator.Persistent);
             var entity = GetEntity(TransformUsageFlags.Renderable);
             AddComponent(entity, component);
        }
    }
}

But there is error like this .
9064024--1253581--upload_2023-6-8_0-1-49.png

I want to change this componentData in runtime (PerInstance) , so BlobAsset doesn’t work for this.
ISharedComponent is not for AddComponent(xxxx).

Is there anyone who knows about this?

ECS Material Property Overrides have to be fixed sized. For dynamic sized stuff, you need a separate graphics buffer and set that as a global shader buffer, than have normal ECS material property overrides index into it.

It is ok to be fixed size array,like float[8] .And I hope it works as perInstance property , not global float array.
But I don’t know how to declare it in IComponentData. Could you please give some samples?

Yes. Though Shader Graph won’t know how to generate it so you’ll have to make the shader yourself (or inject custom code into Shader Graph).

It just gets raw MemCpy-ed, so you could have 8 individual floats in your struct, or two float4s, or a float2x4. Totally up to you.

I don’t have any examples for fixed sized arrays yet, but I do have some real-world examples of indexing into separate buffers, which I use for skinned mesh animation rendering. Is that something you’d be interested in?

OK , I know it. Actually, they are totally certain fields in struct, not like float[8] in shader.There will be many propertys in shader to fit feild in struct , but it can work. It seems that there is no better solution.