I am just starting to work with Job System and Burst Compiler(1.4.0) and I have a problem.
I have a structure with arrays of different types. When I try to create a NativeArray out of it, I get an error on startup "InvalidOperationException: 'Data' used in NativeArray<> must be unmanaged (contain no managed types) and cannot itself be a native container type." I don't know what to do, I tried to use native arrays instead of unity arrays, but I still get the same error.
My main task is to pass triangles, vertices and normals to Job to generate a mesh.
The structure is used in another class to return the required parameters
Class:
public class Model
{
public List<GameObject> gameObjects;
public Vector3[] vertices;
public int[] triangles;
public Vector2[] uvs;
public Vector3[] normals;
public Data GetData()
{
return new Data(vertices, triangles, uvs, normals, gameObjects.Count);
}
}
Structure:
public struct Data
{
public readonly int gameObjectsCount;
public readonly Vector3[] vertices;
public readonly int[] triangles;
public readonly Vector2[] uvs;
public readonly Vector3[] normals;
public Data(Vector3[] _vertices, int[] _triangles, Vector2[] _uvs, Vector3[] _normals, int _gameObjectsCount)
{
vertices = _vertices;
triangles = _triangles;
uvs = _uvs;
normals = _normals;
gameObjectsCount = _gameObjectsCount;
}
}
The line that cause the error:
int length = 10;
NativeArray<Data> _data = new NativeArray<Data>(length, Allocator.Persistent);
Does anyone have an idea of how to get around this? Thanks in advance.