Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] ComponentDataFromEntity for IBufferElementData?

Discussion in 'Entity Component System' started by JamesWjRose, Nov 17, 2019.

  1. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    EDIT: The solution, thanks to GilCat is:
    For IBufferElementData you should use BufferFromEntity
    ----------------------------
    Hello,

    I have a job where I need access to an array of float3. I can use ComponentDataFromEntity for IComponentData, however when I attempt to do so for an IBufferElementData I get a error:

    public ComponentDataFromEntity<LanePointsComponent> LanePointsFromEntity;

    public struct LanePointsComponent : IBufferElementData
    {
    public float3 value;
    }

    The "LanePointsComponent" is underlined in red and states: "The type 'LanePointsComponent' cannot be used as a type parameter 'T' in the generic type or method 'ComponentDataFromEntity'. There is no boxing type from LanePointsComponent to iComponentData"

    Which, okay, I get. So... what is the answer? Can I, or should I include this type as part of another component:

    ie:
    public struct ConnectionDetails : IComponentData
    {
    public int ConnectionIdentity;
    public int LaneIdentity;
    public LanePointsComponent LanePoints;
    }

    Thanks kindly for any info.
     
    Last edited: Nov 17, 2019
  2. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    JamesWjRose likes this.
  3. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Thank you VERY much. And so quick too. Have a great week.