Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

CalculatePath always Invalid [SOLVED]

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

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,306
    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:
    68
    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?
     
    MH2B likes this.
  3. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,306
    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:
    3,296
    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:
    3,296
    Actually, nvm. It does work with 1.2 height, but anything lower is just causing PathInvalid.
     
  6. Xhitman

    Xhitman

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

    Any idea?
     
  7. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    Happens the same, always invalid path, i check it at start and gives invalid path, i changed height but doesnt matter, i have no way to know if path is invalid, agent.destination gives a path as models move but the path is always invalid
     
  8. MH2B

    MH2B

    Joined:
    Nov 24, 2018
    Posts:
    5
    Thanks, Changing the height of the agent from AI-Navigation window worked for me.