Search Unity

How do I change baked Navmeshes during runtime?

Discussion in 'Navigation' started by mikelowefedex, Oct 25, 2020.

  1. mikelowefedex

    mikelowefedex

    Joined:
    Sep 29, 2020
    Posts:
    139
    Hello,
    I have a scenario where during editing, a square room that is 10 by 10 by 2 units wide sits in the middle of my scene, and has doorway on the front, right, back and left walls of the room. There is also a hole in the middle of the floor and ceiling of the room (for a staircase to fit). When the game is ran, the room 'instantiates' to 3 by 3 by 3 rooms that are next to each other side by side, with the staircases in place (to make the game look like a mansion with endless rooms). Every time the player exits a room, the player's position 'modulates', so if the player exits out of the right side of a room, the player is back at the left side of the next room, but the rooms change (to make it look as if the player is going from room to room). Depending on what level the player is on, will also depend on what doors and staircases will appear in whatever room the player is virtually in.

    I have a NavMesh baked on the ONE room during editing mode, before the room gets instantiated into multiple rooms during runtime. I want to create a game object that chases after the player, and would like a navmesh to update itself every time the player exits a room, so that the mesh changes according to where the doors and staircases virtually are. I heard the NavMeshSurface class can update navmeshes during runtime, but that was for the earlier versions of Unity, where pathfinding wasn't built in. I am using version 2021.1.0a2.727. What would be the best way to get updates on nav meshes during runtime for that version of Unity? Thank you.
     
    Last edited: Oct 25, 2020
  2. mikelowefedex

    mikelowefedex

    Joined:
    Sep 29, 2020
    Posts:
    139
    I also want to update the navmesh every time I change rooms because I have the doors to each of the different rooms set up to be at a random seeded position according to the room number I am in, so the pathfinding would always change when I change rooms. Is there way in the 2021 version of Unity to update nav mesh surfaces (if navmesh is now a built in feature in Unity)?
     
  3. mikelowefedex

    mikelowefedex

    Joined:
    Sep 29, 2020
    Posts:
    139
    Is there a Unity 2021.1.0a2.727 version of NavMeshSurface.BuildNavMesh() (for updating nav meshes at runtime)? I can't find the NavMeshSurface class or .cs script anywhere.
     
  4. mikelowefedex

    mikelowefedex

    Joined:
    Sep 29, 2020
    Posts:
    139
    I am trying to update the navmesh after instantiating something like this, to where not all the rooms have staircases. The 1x1x1 room instantiates to 3x3x3 at runtime, but the navmesh doesn't update. Since navmesh is built in to Unity in the 2021 version, I was wondering how the best way is to update navmeshes during runtime in the 2021.1.0a2.727 particular version of Unity.
     
  5. mikelowefedex

    mikelowefedex

    Joined:
    Sep 29, 2020
    Posts:
    139
    The navmeshes work only for that ONE room during editing mode...
     

    Attached Files:

    • nav.jpg
      nav.jpg
      File size:
      199 KB
      Views:
      331
  6. mikelowefedex

    mikelowefedex

    Joined:
    Sep 29, 2020
    Posts:
    139
    I figured it out.
     
  7. DXWarlock

    DXWarlock

    Joined:
    Oct 21, 2020
    Posts:
    3
    What was your solution Mike? I and struggling with the same situation.
    Player adding rooms to the play area during gametime for the AI to travel around.
     
  8. mikelowefedex

    mikelowefedex

    Joined:
    Sep 29, 2020
    Posts:
    139
    I figured out that I was using Unity's builtin pathfinding system, instead of downloading the NavMeshSurface package, creating an empty game object, setting the pathfinding attributes and then using the NavMeshSurface.BuildNavMesh() function during runtime.