Disable temporarily pathfinding

Hello! How can I efficiently/easily disable pathfinding (so pathes stay in queue), while I update my point graph? Problem is weird, I do use UpdateArea(GraphUpdateObject o), but then I also do my own background thread processing (which takes seconds) before I push update to graph. How can I disable/block pathfinding between and how can I detect when pathfinding is done? So I can just swap between pathfinding or updating mode?

Also second question, I dont want to create another thread. Is there any more efficient way than RegisterSafeUpdate? I call this function 50k+ times and I think it’s too much.

Hi

When using RegisterSafeUpdate, the pathfinding threads will be paused and the paths will stay in the queue.
RegisterSafeUpdate only blocks while the callback is running however, but you can block for a longer period of time using AstarWorkItem like this.

 AstarPath.active.AddWorkItem(new AstarWorkItem(force => {
     // This will be called repeatedly until the work item returns true
     // If the 'force' parameter is true then the work item *must* block until it is done.
    // 'force' will be set to true for example if AstarPath.active.FlushWorkItems is called
     if (workIsComplete || force) {
          // Indicates that the work item is done and pathfinding can be resumed
          return true;
     } else {
          // Wait a bit longer
          return false;
     }
 }));

Hello, thanks! Will try this approach.

Do those work items run on main thread or background though?

They run on the main thread.

Ah that is a bummer. Can’t I make it run on background thread? I kinda have my own “work/task unit” implementation that run on background thread and can switch back to unity thread.

Thanks for fast reply!

Hi

If you run it in your background thread you should be able to just check if the background thread is finished in the work item callback. Or you can use something like WaitHandle.WaitOne(0).