How to wander with respect to Area Cost

I am using my own Wander Script that uses SamplePosition to find a position to go to, for some reason this doesnt always return a position on the NavMesh but I can live with that for now.

protected bool SamplePosition(Vector3 position)
        {
            NavMeshHit hit;
            return NavMesh.SamplePosition(position, out hit, navMeshAgent.height * 2, NavMesh.AllAreas);
        }

I am wondering if I can get this to respect the area costs somehow? so that if there is a road they will pick a random point on a road instead of a random point in rough grass for example.

Much like this video: https://arongranberg.com/astar/docs/images/random_point.mp4

In this video it doesnt just walk around the high cost area, it actually chooses it less times as a destination too, which is what I want.

Not sure if I understood you correctly, but couldn’t you sample the environment with areaMask so that you just pick spots on the preferred areas, like roads?

Well, that would make it so it never picks a spot on the grass EVER, I want it to use the cost system. So its just 90% more likely (for example) to go on the road.

SamplePosition does not use the cost system, so no that is not possible. But you can easily circumvent this buy using sample SamplePosition for every specific layer and do the random picking yourself.