[GenerateAuthoringComponent] on IBufferElementData with non-serializable field

using Unity.Entities;
using Unity.Mathematics;
using System;

[GenerateAuthoringComponent]
[Serializable]
public struct MyElement : IBufferElementData
{
    public half value;
}

When the authoring component is attached to GameObject, List doesn’t show up in the inspector (which is the correct behaviour I guess, maybe not for math types though).
Converting the object results in the following:

Unity.Entities.Hybrid.BufferElementAuthoring`2[TBufferElementData,TWrappedValue].Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager destinationManager, GameObjectConversionSystem _) (at Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.Hybrid/BufferElementDataAuthoringComponent.cs:20)```
Which is happening due to the List<MyElement> being null because it was not set in the inspector as far as I can tell.

Hi, have you solved the problem, I’m having the same one and I do not know how to solve it.

Nope, in my case I switched to float instead of half for now.

Why not create your own authoring component instead of using a generated component with the attribute? For the authoring component, use a float with a range attribute to clamp its value within the range you need for runtime then in the conversion just cast the float into a half.

It looks like half is not currently marked Serializable (and thus won’t show up in the inspector). We will fix this in an upcoming Unity.Mathematics release. Thanks for bringing it up!

1 Like