Search Unity

How NavMeshAgent choose a NavMeshSurface to move on?

Discussion in 'Navigation' started by Shiina011, Jun 9, 2021.

  1. Shiina011

    Shiina011

    Joined:
    Oct 1, 2020
    Posts:
    46
    I have 3 pre-baked NavMeshSurface prefab.

    What I want to do is manually choose what NavMeshSurface the AI could move on based on the 3 that I have by code.

    Is something like this is possible?
     
  2. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    There's a couple ways I see you can do that.
    You could have 3 different agent types, all configured the same (or different, shouldn't actually matter other than the player may notice the difference if they are large variations on configuration), then swap the NavMeshAgent's agent type at runtime.
    Or, you could bake the Navmeshes at runtime just before you need them and override the same NavMeshData registered to the NavMesh system so the player will automatically swap between them.
    You can learn more about runtime baking from my tutorials:
    1. Runtime Baking 1
    2. Runtime Baking 2
    3. Runtime Baking 3