NavMesh working, but SamplePosition returns false - RPG course

So first off, this did result from a detour from the basic course. Using the Terrain that the course does, everything works fine, but if I use objects as floor tiles (set to static and baked) SamplePosition always returns false, with a mask of 0.

The NavMesh shows up as blue with the gizmo’s, and it’s perfectly walkable and workable in every other way, but I’m trying to set the walk cursor by detecting the NavMesh, which doesn’t work with this problem.

I can only imagine there’s some sort of ‘aiming’ issue with the NavMeshHit, but having done the check with a single Raycast and a RaycastAll array, nothing works.

Ideas? Would appreciate the help!

~ Zephyr

Some code may help I imagine! Though without linking or dumping a ton, it’s pretty basic stuff. The SamplePosition below is the false return. testCursor is a struct with variable types that should be clear from their usage.

private void RunAllCursorTests()
            RaycastHit hitRay;
            testCursor.hitCheck = Physics.Raycast(GetMouseRay(), out hitRay);

            testCursor.hitPoint = hitRay.point;

            testCursor.hitNavCheck = NavMesh.SamplePosition(testCursor.hitPoint, out testCursor.hitNavPoint, maxNavCheckDistance, NavMesh.AllAreas);

            testNavPath = GetNavMeshPath(transform.position, testCursor.hitPoint);
            bool isBlocked = NavMesh.Raycast(transform.position + new Vector3(0, .5f, 0), testCursor.hitPoint, out testNavPath.navPathEnd, NavMesh.AllAreas);

            //if (testNavPath.navPathDistance > maxPathLength) { return; } // Path too long, escape Update()

            testCursor.hitRayAll = RaycastAllSorted();


I don’t have a lot of ideas here, since this code looks fairly straightforward… the only thing I can think of off of the top of my head is to ask do the floor tiles have a collider?

The floor tiles have a collider and are static for the NavMesh. There’s also a Plane underneath the whole map with just a collider, not static. I’ve tested disabling the collider on one at a time, then the static check, and then disabling the Plane and tiles entirely one at a time with no luck (all with re-baking the mesh in between).

What gets me is the code obviously works, since the scene with Terrain functions just fine. I may need to try making another new scene and testing a bit of NavMesh, or adding a piece to the Terrain scene. I’ve really no idea XD

Sufficiently confused now (as if I wasn’t before XD).

Dropped a floor tile into the Terrain scene, right at the edge of the terrain, turned it static and baked it, and SamplePosition returns just fine. Created a path on the Plane scene that stretches out over the edge of the Plane - nothing, still all false.

Copy/pasted the whole map into a new scene and it works just fine…
Something’s wrong with the scene itself then? sighs At least it’s a solution, of sorts.

Scratch that, it works until I get everything back into place.
Something that I’m setting up breaks it…

2nd Edit:
Found it. Max NavCheck distance in PlayerController was too small of a number. Which makes total sense. Of course XD.

I’d set it ridiculously low after reading enough advice on that improving the position check, with regards to actually finding the closest NavMesh point. It never seemed to ‘actually’ make a difference, but I left it low just in case.

So, point of note: don’t set that distance check too low (1 works fine, .001 does not) or it screws up SamplePosition.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.