My map mesh is quite large and I used the min region area setting to remove most of the islands which formed under buildings. However a few such islands still exist even when the islands are obviously smaller than the min region area setting (which is 20,000). Either I am not understanding this setting correctly or this looks like a bug in the NavMesh feature. My enemy AIs sometimes spawn in these islands which are inside of the mesh so they[27105-screenshot+2014-05-30+14.02.55.png|27105] cannot be seen or reached. I am using SamplePosition with a random generated position within the NavMesh. I have included a screenshot taken from underneath the NavMesh to clearly show an island and the NavMesh Bake settings.
The NavMesh is an awesome feature and I would like to learn how to avoid these islands or how to program around them.[27105-screenshot+2014-05-30+14.02.55.png|27105]
Try using the free Navmesh Cleaner asset. It automatically creates NonWalkable volumes around areas that don’t seem reachable. However, it doesn’t take NavMeshLinks into account, but you can place a bunch of walkable indicators to allow generation on those desired islands.
if (NavMesh.SamplePosition(hit.point, out NavMeshHit nmHit, 2f, NavMesh.AllAreas))
{
// Test if sampled position can be reached from NavMeshAgent's current position (is not an island)
var testPath = new NavMeshPath();
_navMeshAgent.CalculatePath(nmHit.position, testPath);
// If reachable, use it
if (testPath.status == NavMeshPathStatus.PathComplete)
{
return nmHit.position;
}
else
{
// retry
}
}
In OP’s case, just use CalculatePath to a ‘known good’ part of the map after spawning an enemy. If PathComplete is false, then they are on an island, so move them somewhere else and check CalculatePath again.