Search Unity

Multiple NavMesh Accessing

Discussion in 'Navigation' started by zIyaGtVm, Nov 2, 2018.

  1. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    I'm using 2 navmeshsurface components on one mesh object, each has a different agent type .
    While calling NavMesh.XXX(Singleton class to access the baked NavMesh) it always gets the first one.
    How to access another navmesh? Any advice would be appreciated.
     
    phobos2077 likes this.
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Write your own class and assign both NavMeshes to that one. The NavMesh class was never really adapted to work with multiple navmeshes as far as I know.
     
  3. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Thanks!
    But my problem is that I don't know how to distinguish and hold 2 navmeshs first (through code) so that I could assign them later.
    I was tring to get [NavMeshHit]s separately on two navmeshsurface component.

    Otherwise, is there anyway to apply [SamplePosition] on NavMeshSurface?
    https://docs.unity3d.com/ScriptReference/AI.NavMesh.SamplePosition.html
    public NavMeshSurface surfacePlayer;
    public NavMeshSurface surfaceEnemy;
     
    phobos2077 likes this.
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Unfortunately you'd have to solve that by exposing the NavMeshComponents for that new class in the editor, then drag and drop in the corresponding NavMeshes. Not very generation-friendly but there isn't really a way to differentiate, indeed.
    If I look through the source code it seems like you can't call SamplePosition on an individual Component, unfortunately.
    What exactly do you want to use the SamplePosition for?
     
  5. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    I want to use SamplePosition to return different hit (out AI.NavMeshHit), in order to get NavMeshSurface's height offset individually. Then I can apply this offset to agents' baseOffset. :confused:
    e.png
     
  6. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    hmmm, wouldn't it be a lot simpler to just make a trigger area that offsets a NavMeshAgent's base offset when entered and lowers it again on exit?
     
  7. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Worth a try Thanks! Just want to calculate each surface's height offset more accurately.That's the reason why I used SamplePosition.
     
  8. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I get that, but NavMesh Heights aren't always reliable (and heightmeshes apparently aren't implemented for NavMeshSurface Components right now, meaning stairs etc would quickly give wrong results) and they're kindof expensive since they go through the NavMesh Queries which are limited in number per frame. You're probably better off with a method like what I proposed here.
     
  9. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Yeah I got it, I hope NavMeshSurface Components could implement heightmeshes someday.
    It's really nice of you to discuss this with me ,Thanks and I'll give it a go.:)
     
  10. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    You're welcome, that's exactly what this place is for after all ;)
     
    zIyaGtVm likes this.