Search Unity

ICompoentData must be blittable(No managed object is allowed on the struct)

Discussion in 'Data Oriented Technology Stack' started by X301, Mar 21, 2018.

  1. X301

    X301

    Joined:
    Jan 24, 2013
    Posts:
    108
    Hi I'm trying to convert my grid pathfinding code over and I'm running into a issue. I'm trying to use a array to hold a collection of grid nodes. I'm getting a error saying the collection bust be blittable and no managed object is allowed on the struct. I'm looking at the examples and can't find any components that are using collections.

    Code (CSharp):
    1. using System;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Mathematics;
    5. using UnityEngine;
    6.  
    7. [Serializable]
    8. public struct ComponentDataGrid : IComponentData
    9. {
    10.     public GridNode[] gridNodes;
    11. }
    12.  
    13. [Serializable]
    14. public struct GridNode
    15. {
    16.     public float3 worldPosition;
    17.     public int3 index;
    18. }
    19.  
    20. public class ComponentGrid : ComponentDataWrapper<ComponentDataGrid> { }
     
  2. holo-krzysztof

    holo-krzysztof

    Joined:
    Apr 5, 2017
    Posts:
    19
    I think you need to use NativeArray or some other unity collection.
     
  3. X301

    X301

    Joined:
    Jan 24, 2013
    Posts:
    108
    Iv tried that and that does not work eather.
     
  4. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    144
    Currently you have to use a ISharedComponentData as arrays and all native containers are not blittable. Afaik Unity is working towards to make NativeArrays possible to use in IComponentData
     
  5. X301

    X301

    Joined:
    Jan 24, 2013
    Posts:
    108
    Thank you. Can I use job system with ISharedComponentData?
     
  6. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    144
    You can, but you have to use native containers inside jobs.
     
    Last edited: Mar 24, 2018
  7. X301

    X301

    Joined:
    Jan 24, 2013
    Posts:
    108
    Thanks again.
     
  8. Caiuse

    Caiuse

    Joined:
    Jan 6, 2010
    Posts:
    29
    Please could you briefly expand on this, I'm do something very similar setting up a graph structure.
     
    MarkusGod likes this.