[Solved] Graph.PointOnNavmesh returns null even though player is on the graph

Hello,

I have this script that checks if the player is on the graph, which works 100% on my other scene. Im passing the player position. Both scenes use Recast.

    private bool IsTargetReachable(Vector3 targetPos)
    {
        var graph = AstarPath.active.data.recastGraph;
        var targetNode = graph.PointOnNavmesh(targetPos, null);

        if (targetNode != null)
        {
            return true;
        }

        return false;
    }

No matter where am at it always returns false because targetNode is null. I have been using the same code for months on my other terrain and not sure why it wouldnt work here. The only difference is that Im using cached graph now.

Edit: I turned off Cache startup and same problem happens.
Edit2: After some time spent I decided to rebake the graph a couple of times and it works now!

Alright. I’m not sure what the problem was… but it seems to be resolved now?

1 Like