Error Message - Finding a Path to Infinity?

So I’m currently getting an error, where when it’s trying to calculate the path but it can’t reach that point, it’s trying to find a path using a Vector3 with Infinity at every point.

I tried to set a safety line that says
if (navMeshHit.position == Vector3.positiveInfinity ||
navMeshHit.position == Vector3.negativeInfinity) return false;

and THEN using that to try to find the path, but it doesn’t seem to be helping stop this from happening.

Here’s the error message:

CalculatePolygonPath: invalid input position(s). Source position { -19.149866, -0.009147, -23.018562 }. Target position { Infinity, Infinity, Infinity }
UnityEngine.AI.NavMesh:CalculatePath (UnityEngine.Vector3,UnityEngine.Vector3,int,UnityEngine.AI.NavMeshPath)
(etc)

Any ideas as to what’s going wrong?

It looks like you’re trying to calculate a path when there is no hit in InteractWithMovement (PlayerController).
Paste in your InteractWithMovement and we’ll take a look.

Thank you! Your hint helped me to figure it out. I was missing this

if (!navMeshHit.hit) return false;

After calling NavMesh.SamplePosition() to verify that the NavMeshHit was actually a successful hit (I checked the documentation and that helped me to discover the “hit” property of MavMeshHit). Once I added that in, it fixed the problem.

But then, I started getting an Index Out of Bounds error! So I did some testing, and eventually just figured out I needed

for(int i = 0; i < path.corners.Length - 1; i++)

for my loop, including the Length - 1 specifically. Maybe I was overtired but I thought Sam said to NOT include it for some reason? Anyways, once I did that all the out of bounds errors went away, and now the Navigation works like it’s supposed to.

Thank you for your help (and for helping me to think more about what my code was doing!), I appreciate it!

1 Like

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

Privacy & Terms