Pathfinding: A* Pathfinding Project Pro
DunGen provides integration for Aron Granberg's powerful A* Pathfinding Project Pro asset, allowing you to automatically generate or update pathfinding graphs at runtime after your dungeon layout is created.
Third-Party Asset Required
A* Pathfinding Project Pro is a separate asset available on the Unity Asset Store and must be purchased and imported into your project.
Prerequisites
Install A* Pathfinding Project Pro into your Unity project.
Setup
- Ensure you have an Astar Path component configured somewhere in your scene (typically on a dedicated manager GameObject). You need to have at least one Recast graph type set up. Configure the basic settings of your graph (like agent size, collision masks, etc.) as needed before runtime.
- Locate the GameObject in your scene that has the
Runtime Dungeoncomponent attached. - Add the
A* Pathfinding NavMesh Generatorcomponent to this same GameObject (Add Component > DunGen > NavMesh > A* Pathfinding NavMesh Generator).
This adapter component will automatically run during DunGen's post-processing phase after the dungeon geometry is finalized.
Adapter Component Settings
The specific settings on the A* Pathfinding NavMesh Generator component might vary slightly depending on DunGen and A*PP versions, but they typically include:
Priority: Determines the order in which multiple DunGen adapters are run. Lower numbers run first. The default is usually sufficient.- Settings for Door Handling: Specific fields related to tags for open and closed doors (see Handling Doors below).
Handling Doors
A common requirement is making doors block pathfinding when closed and allow it when open. The recommended approach with A*PP and DunGen relies on Tags:
- Create a Layer: In Unity's Tag & Layer Manager (
Edit > Project Settings > Tags and Layers), create a new physics layer specifically for your doors (e.g., "Doors"). - Configure A* Graph: In your Astar Path component's graph settings (e.g., for your Recast Graph), find the collision testing or masking options. Ensure that the "Doors" layer you created is excluded from the mask used for building the graph. This prevents the graph from being built under the physical space occupied by closed doors.
- Set Door Prefab Layer: Make sure all door prefabs used by DunGen (Connectors, Locked Doors, etc.) are assigned to the "Doors" layer you created.
- Configure Adapter Tags: In the
A* Pathfinding NavMesh Generatorcomponent settings, assign the "Open Door" and "Closed Door" tags you created in A*PP to the corresponding fields in the adapter. - Configure AI Agents: In your A* agent scripts (like
AIPath), configure the "Traversable Tags" to include your standard walkable tag(s) and the "Open Door" tag, but exclude the "Closed Door" tag.
This setup ensures that the initial scan ignores closed doors, the adapter applies initial tags correctly, and door objects dynamically update path availability by changing tags, which your AI agents respect.
By using the A* Pathfinding NavMesh Generator adapter and correctly configuring layers and tags, you can effectively integrate A* Pathfinding Project Pro with your DunGen-powered procedural dungeons.