Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

CalculatePath always Invalid [SOLVED]

Discussion in 'Navigation' started by CDF, Jul 2, 2017.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    781
    I'm getting back into Nav Meshes again :)

    but my CalculatePath call is always invalid... UNLESS... I set the origin and target to sampled positions on the nav mesh.

    Do I really need to sample NavMesh positions everytime I want to calculate a path?

    Shouldn't the CalculatePath call do this automatically?
    I have 2 positions, they may/may not be exactly on the nav mesh surface. Some points might be offset. Seems very strange to me that I have to change the positions to match a point exactly on the surface to get a valid result.
     
  2. adriant

    adriant

    Unity Technologies

    Joined:
    Nov 1, 2016
    Posts:
    31
    CalculatePath does try to map the positions to the NavMesh, but the search distance depends on the radius and height of the agent type you specify, otherwise it falls back to the radius and height of the default agent, which usually is 0.5 horizontally and 2.0 vertically. World positions that are further away from the NavMesh than these values will not be mapped.
    Does it work for you when the positions you pass to CalculatePath are within these ranges relative to the NavMesh?
     
  3. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    781
    Ah I see, yeah I had to change my agent height to a large value. I'm building a game with water waves, the waves offset the positions so yeah, making the height large enough does the job.

    Thanks
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,013
    I've encountered same problem with NavMesh.CalculatePath();
    Path is always returns as PathInvalid if the height is set lower than 1.5. Can't figure out why it's happening.
    I'm doing it like so. I doubt it can't find the start position, hence it doesn't print out the error. This feels like a bug.

    Code (CSharp):
    1. NavMeshHit hit;
    2. if (NavMesh.SamplePosition(samplePosition, out hit, 1000, NavMesh.AllAreas)) {
    3.     if (!NavMesh.CalculatePath(hit.position, destination, NavMesh.AllAreas, _path)) {
    4.         Debug.Log(_path.status);
    5.     }
    6.  
    7.     ProcessPath();
    8.  } else {
    9.        Debug.LogError(this.ComponentName() + "Entity is too far from the nav mesh");
    10. }
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,013
    Actually, nvm. It does work with 1.2 height, but anything lower is just causing PathInvalid.
     
  6. Xhitman

    Xhitman

    Joined:
    Oct 30, 2015
    Posts:
    297
    I have the same problem , but my agent radius is 8, height is 20.

    Any idea?