void
AddWorkItem
(
)
Add a work item to be processed when pathfinding is paused.
The work item will be executed when it is safe to update nodes. This is defined as between the path searches. When using more threads than one, calling this often might decrease pathfinding performance due to a lot of idling in the threads. Not performance as in it will use much CPU power, but performance as in the number of paths per second will probably go down (though your framerate might actually increase a tiny bit).
You should only call this function from the main unity thread (i.e normal game code).
AstarPath.active.AddWorkItem(new AstarWorkItem(() => {
// Safe to update graphs here
var node = AstarPath.active.GetNearest(transform.position).node;
node.Walkable = false;
}));
AstarPath.active.AddWorkItem(() => {
// Safe to update graphs here
var node = AstarPath.active.GetNearest(transform.position).node;
node.position = (Int3)transform.position;
});
You can run work items over multiple frames: AstarPath.active.AddWorkItem(new AstarWorkItem(() => {
// Called once, right before the
// first call to the method below
},
force => {
// Called every frame until complete.
// Signal that the work item is
// complete by returning true.
// The "force" parameter will
// be true if the work item is
// required to complete immediately.
// In that case this method should
// block and return true when done.
return true;
}));