Search Unity

Prebaked Navmeshes on one GameObject

Discussion in 'Navigation' started by MA1900, May 1, 2019.

  1. MA1900

    MA1900

    Joined:
    Jan 29, 2019
    Posts:
    2
    Hey,
    is it possible to have two different Navmeshes on a GameObject and to choose between them? Because of the delay, baking at runtime is not possible. So can I bake two Navmeshes on one GameObject but just use one?
    Thanks in advance and best regards
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Why would you want to do this, exactly? Unity actually DOES support multiple Navmeshes, but for a very specific reason: different agent types.
    Say you have two different characters, one is big, and the other is small. There will be places in your level the big one can't reach that the small one can. For those reasons, you make two different agent types that fit the characters, and then bake a NavMesh for each agent type.
    This does come with the caveat that you can't just pick which Navmesh to follow, instead, your agents will always follow the mesh that fits for their agent type.
     
  3. MA1900

    MA1900

    Joined:
    Jan 29, 2019
    Posts:
    2
    First, thanks for your answer.
    My problem is the delay, when I bake the navmesh at runtime. There are a few barriers that appear at runtime.
    I can't use navmesh obstacles because of the shape of the barriers.
    So I need two Navmeshes, one with the barriers and one without them. There is just one agent.
    Is this possible and can I switch between this two prebaked Navmeshes?

    Thanks in advance and best regards
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Like I said before, you can't freely switch between NavMeshes, an agent will only follow the one mesh that's baked for its agent type.
    What you COULD do, and this is a roundabout hack, is have those barriers be NavMesh regions which one agent type cannot cross, and the other one can. Then you bake those two out, and you swap your agent's type depending on whether the barriers are activated or not. Keep in mind this might still result in some unexpected behaviour, but it's a hack after all.
    I would still suggest trying to approximate the barriers with NavMeshObstacles instead, but here's an alternative.
     
    MA1900 likes this.