I’m working on a pretty large grid (~30x15) and a very high maximum move distance, and performance of this function seems quite bad . While it’s not noticeable when I have a smaller grid, or smaller maximum move distance, I notice my game freezing when this function gets called now.
I’m taking every grid object within the maximum move distance, checking if it’s walkable, and then calculating the Path there, to see if it’s reachable and if the path is not too long.
Trying to calculate the path to every single possible grid position this way seems to get very performance-hungry very quickly. I hope to get some suggestions / approaches on how to make this more manageable.
And ofc thanks CodeMonkey for the amazing course, it’s helped and taught me a ton already.
Edit: Doing it once to check for valid positions before moving is fine performance wise (albeit with a noticable dip in fps), but my PC starts suffering if I want to use it for things like:
- displaying and updating the grid visuals, to display the path the player would take to get to the mouse position, and showing all valid positions the player can move to
- calculating it from multiple different positions to find the best possible enemy AI actions
Edit#2: I am working with a Hex grid in case that would change things in a significant way. Currently brainstorming some ideas on how I can significantly increase the amount of GridObjects that I can add to the valid list, or eliminate, before I actually have to call pathfinding on them.