How to query recast graph from inside a Unity job that uses BurstCompile?

Hi !

From inside a job that uses BurstCompile, having a recast graph and a float2(x,z) pointM, I need to compute the point float3 (x,y,z) pointN that is on the walkable area.

If I do:
[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float3 GetPoint(float2 pointM)
{
var recastGraph = AstarPath.active.data.recastGraph;
var pointN = recastGraph.GetNearest(new Vector3(pointM.x, 0f, pointM.y)).position;
return pointN;
}

But I get this compile error in Unity: Burst error BC1042: The managed class type AstarPath is not supported. Loading from a non-readonly static field AstarPath.active is not supported

Before, I was using Unity built-in navmesh with NavMeshQuery.MapLocation and navMeshQuery.IsValid.

Thanks in advance !

Not sure if this will work with AstarPath, but I had a similar issue using a static in bursted jobs. The solution I found was to declare my static variable something like this.

private static readonly SharedStatic<AstarPath> AstarPathActiveRef;

Probably best to assign AstarPath.active to this readonly static and reference it in your job instead.

Thanks for mentioning SharedStatic, I just learned about it. However, you can’t use classes at all in jobs. The only way would be to create my own Graph struct pass it in the jobs. It will be some amount of work.

Hi

It’s not possible to use any managed data from within burst, and this includes pathfinding data.

You can use a non-bursted job to query the data, but you have to make sure to lock the data as read-only first using AstarPath.LockGraphDataForReading: AstarPath - A* Pathfinding Project

1 Like