public unsafe struct UnManagedNode
{
// A* ready values
public bool visited;
public float finalCost;
public float fromEndCost;
public float fromStartCost;
public int parent;
public UnManagedBounds thisBounds;
public NativeArray<int> connections;
public int id;
public UnManagedNode(UnManagedBounds thisBounds, NativeArray<int> connections, int id)
{
this.visited = false;
this.fromStartCost = float.PositiveInfinity;
this.fromEndCost = float.PositiveInfinity;
this.finalCost = float.PositiveInfinity;
this.id = id;
this.parent = -1;
this.thisBounds = thisBounds;
this.connections = connections;
}
public void Dispose()
{
connections.Dispose();
}
}
then there’s the UnManagedBounds:
using Unity.Burst;
using Unity.Mathematics;
[BurstCompile]
public unsafe struct UnManagedBounds
{
public float3 center;
public float3 extents;
public UnManagedBounds(float3 center, float3 extents)
{
this.center = center;
this.extents = extents;
}
public bool Contains(float3 point)
{
float3 min = center - extents;
float3 max = center + extents;
return point.x >= min.x && point.y >= min.y && point.z >= min.z &&
point.x <= max.x && point.y <= max.y && point.z <= max.z;
}
public float3 ClosestPoint(float3 point)
{
float3 min = center - extents;
float3 max = center + extents;
float3 closestPoint = point;
closestPoint.x = math.clamp(closestPoint.x, min.x, max.x);
closestPoint.y = math.clamp(closestPoint.y, min.y, max.y);
closestPoint.z = math.clamp(closestPoint.z, min.z, max.z);
return closestPoint;
}
}
Unity throws the following error:
InvalidOperationException: UnManagedNode used in NativeArray<UnManagedNode> must be unmanaged (contain no managed types).
Unity.Collections.NativeArray`1[T].IsUnmanagedAndThrow () (at <6f7018b8b8c149e68c4a65a05ac289be>:0)
Unity.Collections.NativeArray`1[T].Allocate (System.Int32 length, Unity.Collections.Allocator allocator, Unity.Collections.NativeArray`1[T]& array) (at <6f7018b8b8c149e68c4a65a05ac289be>:0)
Unity.Collections.NativeArray`1[T]..ctor (UnManagedNode[] array, Unity.Collections.Allocator allocator) (at <6f7018b8b8c149e68c4a65a05ac289be>:0)
OctTree._SetupAndCreateEdges () (at Assets/Game/Scripts/OctTree/OctTree.cs:235)
OctTree.GenerateOctTreeTraversble () (at Assets/Game/Scripts/OctTree/OctTree.cs:149)
OctTreeEditor.OnInspectorGUI () (at Assets/Game/Editor/OctTree/OctTreeEditor.cs:112)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass72_0.<CreateInspectorElementUsingIMGUI>b__0 () (at <5d5ebefe97114215928ac1d9cd096522>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)