A* Pathfinding Project

Combine AI mutlithreading with A* Pathfinding



I’m working on a colony sim game, and I have AI agents who are using GOAP System. I implemented multithreading for their planning but i have a problem. When agents do their planning they are relying on Pathfinding to check if some actions can be executed (e.g. to find closest tree or check if he can reach some position). Now, I would like to make Pathfinding of that agent execute on the same thread on which he is doing his planning. Is there a way to do it without changing source code, and if not, can i get some guidance on what should I check out.

Edit: I’m using StartMultiTargetPath.



Sorry for the late answer.
This is not easily done I’m afraid. You can use path.BlockUntilCalculated which will make the path request synchronous, but that will essentially only sleep until the path is done.

It is not easy to do this because each pathfinding thread has a large memory buffer allocated to it which it uses as a scratch pad during pathfinding so a pathfinding call from another thread would also need this scratch pad which is pretty expensive to allocate.