Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[GenerateAuthoringComponent] on IBufferElementData with non-serializable field

Discussion in 'Entity Component System' started by EvilOctane, Mar 28, 2020.

  1. EvilOctane

    EvilOctane

    Joined:
    Mar 14, 2020
    Posts:
    4
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3. using System;
    4.  
    5. [GenerateAuthoringComponent]
    6. [Serializable]
    7. public struct MyElement : IBufferElementData
    8. {
    9.     public half value;
    10. }
    When the authoring component is attached to GameObject, List<MyElement> 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:

    NullReferenceException: Object reference not set to an instance of an object
    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.
     
  2. sirYabar

    sirYabar

    Joined:
    Jan 16, 2018
    Posts:
    1
    Hi, have you solved the problem, I'm having the same one and I do not know how to solve it.
     
  3. EvilOctane

    EvilOctane

    Joined:
    Mar 14, 2020
    Posts:
    4
    Nope, in my case I switched to float instead of half for now.
     
  4. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    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.
     
  5. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    85
    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!
     
    Radivarig likes this.