How to use UnsafeList AddRange

I’m having difficulty understanding how to do this properly. I get an error on line 16 which reads:
“Pointers and fixed size buffers may only be used in an unsafe context [Assembly-CSharp]csharp(CS0214)”

public struct Poly : IDisposable
{
    public bool isClosed;
    public AABB AABB;
    UnsafeList<float3> points;

    public Poly (bool closed)
    {
        isClosed = closed;
        AABB = new AABB();
        points = new UnsafeList<float3>(3, Allocator.Persistent);
    }
    // ...
    public void AddPoints(ref NativeList<float3> pts)
    {
        points.AddRange(pts.GetUnsafeReadOnlyPtr(), pts.Length);
        UpdateBounds();
    }
    // ...
}

Somewhat off topic, but if I have a NativeList and Dispose it, will each Poly item have its Dispose method invoked automatically?

1 Like

GetUnsafeReadOnlyPtr() returns a pointer

You need to use the unsafe keyword and to mark your asmdef as allowing unsafe code to use

No, you need to call them yourself.

1 Like

For anyone else who’s unfamiliar with assembly definitions.