Managing PathFinder GridGraph Across a Game

Hi. I’ve been using a*pathfinding to setup some demo scenes for my game.

Background on my game
It is just like a top down, 2D game. Its a linear game but there are open spaces where combat will happen in some places and exploration will happen in others. I’m using a*path for AI for enemy unit movement. I also have a sidekick type unit that follows the player character around, and so I use the grid graph to path for that unit also.

My questions
To make things work I’ve basically just been expanding the width and depth of the pathfinder to cover my entire play area, since its all contained in one space. This of course works fine for demos, but as its time to expand the game and add traversal throughout many areas, I’ve been starting to think about how to manage it across the entire game. I’m struggling to conceptualize how to manage the Pathfinder across the game and am looking for some pointers.

Scanning the entire map seems like it would be a pretty expensive thing to do. I assume since the world is mostly static that I could scan it and store those graphs somewhere and load them when necessary, but that seems complex.
It seems like I would need the pathfinder to basically follow the player unit so that we’re only scanning things within a certain range, but even then how would I determine when to update the graph? It seems like it might be equally as expensive to scan a new graph every few seconds?

I searched the forums and didn’t quite see questions about this. I’d really appreciate a pointer in the right direction and even some examples out there if they exist. I’m looking to get the pro version, so if examples exist there then that is also fine too :slight_smile:



Have you checked out the example scene called “Procedural”. It shows a grid graph that follows the player around. Just attach the script ProceduralGridMover and it will move the graph automatically.
You can only use it with smallish graphs (e.g. 100x100) because otherwise the overhead of moving it all the time gets a bit high, but it might be usable for your game.

See also

1 Like

Hi Aron,

I think this will work well, but I am encountering one issue where the first scan of the graph will basically treat the boarder of the graph as not traversable, and I guess that is cached until the graph moves completely out of that original space and into a new area. Going back after you’ve completely exited the first boundary will cause everything to work correctly.

I’m attaching a gif that displays this issue.

I thought it might be a result of the graph scanning before everything was fully loaded, so I tried to disable the scan on awake and then delay the scan, but that still doesn’t really seem to have an impact.

If it helps, I’m on 4.2.15.

Hmm. Are you using any erosion on the grid graph? I don’t think that should cause a problem in your version, but it looks like the most likely candidate.

That was it. I wasn’t even intending to use erosion, but I had it enabled. Disabling it is working fine now.

I’ll proceed with this! Thanks for the tips!

1 Like