Correct Approach for Loading/Unloading Map Chunks

  • A* Pro version: 5.3.3
  • Unity version: 6000.0.37f1

Hi!

In my project I am dividing my map into chunks that I can load or unload. Whether they will be prefabs or scenes has not been decided yet and my discoveries with Astar will dictate that decision. Basically, I want to know what is the best way to use Astar with a dynamic map like this, where chunks are loaded/unloaded based on the player’s position. They are not procedural, they are just culled out of the scene so that we keep memory footprint low.

Studying the demos and the documentation, I thought of the following options:

A) Like in the procedural demo, have AStar following the player position. This feels unnecessary since the map is not dynamically generated, it is static, it’s just unloading and loading.

B) Have a very big width (nodes) x height (nodes) graph that encompasses the entire map, and, when a new chunk is loaded/unloaded, I ask AStar to scan that region only (not sure if that’s supported).

C) Have a single graph for each region, whether that is grid, recast, etc…

My question is mainly regarding ease of use and performance, because the game is for mobile. I would like to avoid updating the graph as much as possible, but would also need to know if having a very big graph puts a strain in performance.

If you have any other suggestion as well, please let me know!

Thank you very much!

I still think this is your best bet here. This should still be quicker to calculate a path for, compared to having large (even if sparse) graphs enabled. Give this a try on your target platform. If you run into performance issues we can take a look at what’s eating your performance and suggest something from there.

1 Like

Hi

If possible, try to save the graph to a file at design time, and then load the whole graph when the game starts. This just has a moderate memory cost, and for most use cases not a significant performance cost.
And your agents will be able to pathfind in the whole world at once.
I’m assuming here that you are using a recast graph. Those make the most sense for large worlds.

1 Like

Thank you for the response!

That is correct, I have switched to a RecastGraph but I was previously on the GridGraph. I wonder if the approach of loading the whole graph at the start is fine for now, but would be a problem the more the game grows? And it would be a wasted memory cost, even if moderate, because I will have to cull out agents that are far away anyway, because they have other performance-intensive costs associated.

I was wondering if something like this is supported: I go for a more modular approach for my map chunks where they are grouped into map groups. The map group will have the recastGraph saved at design time, and it encompasses all of the smaller map chunks. When the player switches from one map group to the other, the game unloads the previous recastGraph and loads the next one, in strategic, less busy transition areas. Is that possible?