Optimizing Pathfinding for Large-Scale 2D Game with Chunks

Hello,

Is there a way to optimize pathfinding in my 2D game? I’m developing a game similar to Rimworld with a large number of agents (about 300) using the AI Path script. However, I’m facing a problem where the agents experience performance issues when they are far away from their target The pathfinding process consumes a significant amount of FPS. I’m wondering if there is any way to optimize this.

Alternatively, I have an idea that could potentially optimize the pathfinding process.
Demo
The image showcases large squares representing chunks. My idea is to have the agents first identify the chunks that lead towards their target. Then they find their target with chunks, I would like to find their target with the nodes that are inside the Chunks which lead to target.
Is it possible to implement this approach?

Thank you for taking the time to read my questions :slightly_smiling_face:.

Hi

To start with, are you recalculating the paths optimally?

I’d recommend that you use the “Dynamic” path recalculation mode on your agents, which reduces how often they recalculate their paths when they are far away from their target. Also make sure you have enabled multithreading (A* Inspector → Settings → Threads).