0
\$\begingroup\$

In order to improve the extend ability of our maps, we load different components of the map at run time. The idea is a user can use Unity to make a map, drop it into a folder and it will be loaded.

The problem I'm facing is loading in navmeshes at run time. Before Unity 5, it was possible to give a scene a navmesh using Resources.Load and then NavMesh.Instantiate. NavMesh.Instantiate is now gone for whatever reason, and nothing seems to replace it.

Now when trying to use Object.Instantiate with a navmesh asset and instantiating an agent, I get the error "Failed to create agent because there is no valid NavMesh". Is there any known way to set a navmesh at run time anymore?

\$\endgroup\$
3
  • \$\begingroup\$ If I remember correctly, navmeshes should be stored into levels. If instead of instantiate an object you load additive the level with the additional mesh data it should work fine. \$\endgroup\$ Commented Mar 8, 2015 at 14:04
  • \$\begingroup\$ Which means a scene file for each navmesh, right? I don't believe new scenes can be loaded once the game is built. \$\endgroup\$ Commented Mar 9, 2015 at 2:41
  • \$\begingroup\$ yes you can stream scenes with bundles \$\endgroup\$ Commented Mar 9, 2015 at 10:49

1 Answer 1

1
\$\begingroup\$

If you want to load navmeshes baked with different settings you can not load it additively. What you can do is bake twice in a different scene (resulting in three scenes) then delete the geometry from the scenes containing the navmeshes and load like this:

using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    bool _navMesh1Loaded;
    bool _navMesh2Loaded;

    void OnGUI()
    {
        if (GUILayout.Button("Load NavMesh 1"))
        {
            if (_navMesh2Loaded)
                Application.UnloadLevel(2);
            Application.LoadLevelAdditive(1);
            _navMesh1Loaded = true;
        }
        if (GUILayout.Button("Load NavMesh 2"))
        {
            if (_navMesh1Loaded)
                Application.UnloadLevel(1);
            Application.LoadLevelAdditive(2);
            _navMesh2Loaded = true;
        }

    }
}
\$\endgroup\$

You must log in to answer this question.