Dynamic Level Generation + Runtime Level Changes

Our team is currently building a game of the same vein as Dungeon Keeper. This poses quite a few problems from the pathfinding area as not only do we load in a map at runtime, but the map can change based on player choices.

We seem to have solved the issue of loading the map at runtime by already having a pathfinding object available in a base scene. We can set it to a size which covers the entire map and then reinitialize the graph and this has seemed to work fine in test builds. The issues we are seeing are in terms of the map changes.

Currently, we have built a base floor that is available all the time. We have then placed blocks which players can interact with above them which should cause pathing to fail if it attempts to go that route. The problems I foresee are changes related to the floor itself. Some tiles can cause areas of the floor to be caved in (sometimes drastically enough that units cannot enter that area anymore). Also bridge tiles can be added or removed over water/lava which can also change the pathing at any time.

Based on the tutorials, I see that dynamically added objects will update the graph so that solves anything added. The concern is objects then being removed which I have not been able to find anything to support this. Is there something that can be called counter to how dynamic objects are added in the first tutorial to remove them and update the graph?

Any help would be greatly appreciated. Especially in regards to our methods above of handling the loading of a map at runtime if it is not optimal.

Hi

When adding objects, the graph can be recalculated in a specified area using GraphUpdateObjects (which I assume is what you have read about). This is not restricted to adding objects since it merely recalculates the affected area of the graph. So if you want to remove an object, simply delete it and then call AstarPath.active.UpdateGraphs (…) to recalculate the graph in the affected area so that it is updated to reflect the deleted object.

Hope this helps!