Using Grid Graph Walkable Areas for Diablo-esque Mini-Map

Hello, I’m trying to build a mini-map similar to a dungeon crawler like Diablo like this. I’m currently using the Free version and using the Grid Graph that works like a charm when giving paths for enemies to patrol around. Any idea how to use the walkable areas of the grid graph to create a minimap like the one below? Thanks

Hi

You could potentially use the same methods that the graphs use to draw gizmos.
Take a look at GridGraph.OnDrawGizmos where you will see that it generates a mesh (there is a lot of caching going on there though to avoid recalculating the gizmo meshes too often).

For the borders you might be interested in: https://arongranberg.com/astar/docs/graphutilities.html#GetContours
though post processing using a pixel shader might be easier.

Hi, thanks for your reply! I have gotten started looking at the OnDrawGizmos function on the GridGenerator.cs and also been looking at the CreateNavmeshSurfaceVisualization, which is what seems to be where the surface is visualized.

I’m not so familiar with custom mesh generation and while I see the mesh being created in code, I’m not sure how to convert that Gizmo/Node related code to an actual mesh script like this. Could you give me a few tips? Thanks!

Hi

The easiest way is probably to use this code in the OnRender method:

void OnPostRender () {
    var gizmos = new Pathfinding.Util.RetainedGizmos();
    gizmos.surfaceMaterial = ...; // null will use the default material
    gizmos.lineMaterial = ...; // null will use the default material
    graphs[i].OnDrawGizmos(gizmos, true);
    gizmos.FinalizeDraw();
}

in a script attached to the Camera.
You could also get the meshes by making the RetainedGizmos.meshes field public and then accessing gizmos.meshes[i].mesh.

Thanks for the code, the OnPostRender works like a charm!

I am having problems with your second suggestion, which is actually the method I want to use to get the meshes. I’ve edited the RetainedGizmos.cs by making the “List meshes” public.

I tried to do what you said by accessing gizmos.meshes[i].mesh in the following code, but it returned an error. I tried using the referenced gizmos.meshes[i].mesh with a mesh filter + mesh collider component like this:

var gizmos = new Pathfinding.Util.RetainedGizmos();
meshFilter.mesh = gizmos.meshes[0].mesh;
meshCollider.sharedmesh = gizmos.meshes[0].mesh;

It returns an error saying that cleaning the mesh failed. Am I missing something here? I’d like to be able to create a mesh in the unique shape of the gizmo that’s displayed as walkable, like what is visible in OnPostRender.

Huh. Cleaning the mesh failed, I have never even seen that error.
Note that some of those meshes are ‘line’ meshes which require a special shader. So you should only use the ones where the gizmos.meshes[i].lines boolean is false.

Also note that Unity has a 65000 vertex limit on meshes, so if the graph is large enough the gizmo system will split the mesh up into smaller mesh chunks.