Search Unity

Question Multiple NavMeshModifierVolume components for each agent type

Discussion in 'Navigation' started by billgeekza, May 20, 2022.

  1. billgeekza

    billgeekza

    Joined:
    Dec 28, 2020
    Posts:
    2
    Hello All

    I'm having a fairly hard time understanding how to add modifier volumes to prefabs for different agents.

    I have roads in my game where I want humanoid characters (Agent Type = "NPC Character") to only walk on sidewalks and crossings, and vehicles (Agent Type = "Road Vehicle") to only move on the road surface.

    My prefabs have modifier volumes set to "Not Walkable" for people, and modifier volumes set to "Walkable" for cars. These volumes are identical (I copied the Component and Pasted as a New Component) with the exception of the area type and affected agents:

    upload_2022-5-20_8-7-18.png

    Which results in the "overlapping" navmesh modifiers here:

    upload_2022-5-20_8-8-31.png

    I then have two NavMeshSurface components on my ground plane, one where the people agent is set to Walkable, and another where cars are set to Not Walkable:

    upload_2022-5-20_8-9-49.png

    The road prefab is then instantiated and placed around when loading the level and both navmeshes are recalculated after all objects have been placed:

    Code (CSharp):
    1.             npcSurface.BuildNavMesh();
    2.             vehicleSurface.BuildNavMesh();

    And this is where things start getting weird...

    Everything works for the people in the scene, and they only move where they're supposed to. But as soon as I spawn a vehicle, I get the dreaded "SetDestination can only be called on an active agent that is on a NavMesh" error.

    I've been stuck on this for a few days trying different ideas. Short of creating yet another ground plane to hold the road vehicle surface, and duplicating all of my prefabs and somehow overlapping them, I'm out of ideas here.

    When I enter Play Mode and enable gizmos, I can see that the default NPC Character agents can move where they're supposed to. Great:

    upload_2022-5-20_8-13-29.png

    However when I disable the NPC Character surface and enable the Vehicle surface, I see that nothing is walkable:

    upload_2022-5-20_8-14-27.png



    Am I missing something really simple here? Or am missing a fundamental step somewhere? Any help would be greatly appreciated!
     
  2. billgeekza

    billgeekza

    Joined:
    Dec 28, 2020
    Posts:
    2
    I think I may have just stumbled upon something, so I'll explore this further.

    I've changed the "Default Area" back to walkable for the vehicle surface and I've cleared the nav mesh data in the editor as it's being recalculated through script anyway.

    I can now see some of the road prefabs showing the correct walkable area based on the modifier volumes, excellent! The only remaining puzzle I have is how to make the rest of the level (parks, grass, etc...) not walkable for cars by default, but I'll keep digging into it for now!

    upload_2022-5-20_8-51-50.png

    upload_2022-5-20_8-52-17.png