I have a simple script that loops through all selected units and requests a new A* path for each one.
However, upon creating a callback lambda without the ForEach loop unity crashes immediatly.
public void MoveUnits() {
Entities.WithAll<UnitSelectedTag>().ForEach((
ref Entity entity,
ref UnitFormationSize unitFormationSize,
in int entityInQueryIndex,
in Translation pos,
in Rotation rot,
in UnitSoldierSize unitSoldierSize,
in UnitFormationSpacing unitFormationSpacing,
in UnitSoldiersTotal unitSoldiersTotal
) =>
{
// There must be an AstarPath instance in the scene
if (AstarPath.active == null) return;
// Bunch of unrelated logic that I removed here for the purpose of this post.
var p = ABPath.Construct(
pos.Value,
newPos,
entity,
path => pathQue.Add( (ABPath)path ) // This callback crashes unity
// path => OnUnitPathComplete((ABPath)path) // I've also tried this variation
);
AstarPath.StartPath(p);
}).WithoutBurst().Run();
}
This is defined in the same System class;
I’m using the A* Project Pathfiding Pro version.
I’m really struggling to figure this one out. Could someone give me a clue, please?