0

i am triying to use the unity job system with marching cubes.

here is my job:

private struct UpdateChunksJob : IJobParallelFor
    {
        
        public NativeQueue<NativeChunk> queue;
        public void Execute(int i)
        {
            queue.Dequeue().Chunk.UpdateChunk();
        }
    }

and the queue i am passing in:

public NativeQueue<NativeChunk> chunksToUpdate = new NativeQueue<NativeChunk>();

nativechunk is just a stuct referencing the class chunk:

public struct NativeChunk
{
    public chunk Chunk;
    public NativeChunk(chunk chnk)
    {
        Chunk = chnk;
    }
}

but it is giving this error:

ArgumentException: NativeChunk used in native collection is not blittable, not primitive, or contains a type tagged as NativeContainer
Unity.Collections.CollectionHelper.CheckIsUnmanaged[T] () (at Library/PackageCache/com.unity.collections@1.2.4/Unity.Collections/CollectionHelper.cs:224)
Unity.Collections.NativeQueue`1[T]..ctor (Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at Library/PackageCache/com.unity.collections@1.2.4/Unity.Collections/NativeQueue.cs:282)
worldgen..ctor () (at Assets/worldgen.cs:32)

another strange thing is that this code worked once and then stopped. please help. it would be so appreciated, i am new to jobs and really want to make a job loop over classes but it doesent work.

  • Since `NativeChunk` contains a field that references a managed object (`chunk`), it can't be used inside a `NativeContainer`, in this case the `NativeQueue`. Having a pointer to a referenced object inside a job would break it's thread safety, hence the reason `NativeContainers` and such can only use `structs`, not classes. – Velorexe Mar 08 '23 at 08:33
  • 1
    I managed to rewrite some code and now it works – walter becker Mar 08 '23 at 17:56

0 Answers0