Possible to render one or more navmeshes at runtime?

Hi, is there a possibility to somehow visualize navmeshes/graphs at runtime?
I was thinking of rendering them on a minimap (with some artistic material or shader) to help the players understand where they can go etc.

If there is nothing in-built, maybe we could extract the mesh information from a graph or the pathfinder and send it to a mesh rendering component? How does that sound?

Actually creating a mesh from the nodes was easier and way more performant than I thought.
If someone else wonders, here a little helper to pass on the idea:

[RequireComponent(typeof(MeshFilter))]
public class NavmeshVisualizer : MonoBehaviour
{

    MeshFilter _meshFilter;
    RecastGraph _graph;
    void Awake()
    {
        _meshFilter = GetComponent<MeshFilter>();
        _graph = AstarPath.active.data.recastGraph; // or assign it some other way
    }
    private void OnEnable()
    {
        //subscribe to updates in the graph
        _graph.OnRecalculatedTiles += UpdateNavmeshVisualization;
    }
    private void OnDisable()
    {
        _graph.OnRecalculatedTiles -= UpdateNavmeshVisualization;
    }


    void UpdateNavmeshVisualization(NavmeshTile[] tmp)
    {
        var tiles = _graph.GetTiles();
        int startTile = 0;
        int endTile = tiles.Length;
        CreateNavmeshSurfaceVisualization (tiles, startTile, endTile );
    }
    ...
}

Checkout CreateNavmeshSurfaceVisualization in the NavmeshBase class and follow along with
→ DrawTriangles ->SolidMesh, you’ll figure it out
This creates you basically the mesh that you can pass on to the meshfilter. I won’t post it here, as I don’t know if this stuff is in the pro version or not.

This thread can be marked as solved.

1 Like