NavMeshQuery pointers

First off I was under the impression that native container tracking was not based on the scope of the container, but some other internal tracking was used. Plus I seem to get different behavior here with NavMeshQuery in unit testing then in live code.

In a unit test I can use UnsafeUtility.AddressOf to get a pointer to a query, then UnsafeUtility.CopyPtrToStructure to get back the query and dispose what I got back. No errors or warnings.

Live code I get a not disposed error as soon as the query I created goes out of scope (which I immediately get a pointer to and convert to IntPtr). If it doesn’t go out of scope but later I try to dispose the query via getting it back from UnsafeUtility.CopyPtrToStructure using the IntPtr.ToPointer(), it complains about already being disposed. If I dispose the query via the original reference it works fine. In unit tests disposing the query obtained from the pointer doesn’t complain.

I also get strange error warnings if I create and dispose a query in a unit test, and then play a scene with a navmesh. It spits out like a million warnings about cleaning the query. Next run those are gone.

Edit: those warning on run, my unit testing was also calling MapLocation, so maybe that is what is registering something internally?

Ok so in my unit tests the query was disposed before going out of scope, even though it was indirectly via a pointer. Makes sense.

But still something I’m missing. In live code trying to dispose the query I obtain from CopyPtrToStructure say’s the query has already been disposed. That’s when I have the query stored in a List just to keep a valid reference to it for testing this. This appears to conflict with the behavior I’m getting from unit tests.