News Forums RAIN General Discussion and Troubleshooting How to dynamically create the NavMesh

This topic contains 5 replies, has 3 voices, and was last updated by  GlennNZ 2 years ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12225

    GlennNZ
    Participant

    I have a scene that is created at runtime by loading in xml data. I would then like to create a NavMesh once those objects are added to the scene. Is this possible in Rain{Indie}?

    I see…

    NavMeshRig.NavMesh.GenerateNavMeshGraph();

    Naively I’d think I could do something like

    void Start () {	
       GameObject gameObject = GameObject.Find("Navigation Mesh");
       NavMeshRig navMeshRig = gameObject.GetComponent("NavMeshRig") as NavMeshRig;
       navMeshRig.NavMesh.GenerateNavMeshGraph();
    }

    but it doesn’t seem to do anything. Are there steps that have to be done beforehand or is it just not possible at all?

    #12415

    CodersExpo
    Participant

    I haven’t dynamically created navigation meshes myself but I would probably start looking at RAIN.Navigation.NavMesh namespace

    For example:
    using RAIN.Navigation;
    private RAIN.Navigation.NavMesh.NavMesh _navMesh;

    _navMesh = new RAIN.Navigation.NavMesh.NavMesh();

    _navMesh.StartCreatingContours(RAINComponent component, int threadCount);

    _navMesh.DisplayMode = RAIN.Navigation.NavMesh.NavMesh.DisplayModeEnum.NavigationMesh;

    …but beyond this I’m not sure. Sounds like a good exercise. Maybe Prime or Jester have some tips. I’ll continue to mess with this myself and see what more I can come up with.

    • This reply was modified 2 years ago by  CodersExpo.
    #12418

    CodersExpo
    Participant

    I found an old note from Prime suggesting perhaps to create all your navigation mesh assets at design and register/unregister them at run time.
    RAINNavigationGraph tGraph = NavigationManager.instance.GetNavigationGraph(“graphname”);
    NavigationManager.instance.Unregister(tGraph);

    “The NavMeshRig automatically creates graphs and registers them on Awake. So you could just build all your graphs into the scene and then unregister those that aren’t active. Keep in mind, however, that once you unregister a graph, it is no longer tracked by the NavigationManager – so if you want to activate it again later you will need to either keep it around or regenerate it, then re-register it.

    Another option is to keep all the navmeshes active, but give each a separate graph tag based on the current terrain. Then set your AI to use the graph tag for the current terrain. If you do that, the AI will pick up the correct navmesh automatically.”

    #13381

    philo
    Participant

    Here you go (thanks to CodersExpo).

    http://rivaltheory.com/forums/topic/programatic-navmesh-generation-in-2-0-11/

    I haven’t done any extensive testing but it seems to work for me!

    #13394

    CodersExpo
    Participant

    Right on Philo, thanks for bringing this back to GlennNZ! Now that’s a real community effort!

    #13436

    GlennNZ
    Participant

    Thanks guys. Yes, that 5th May reply by philio in the above linked thread is indeed the solution I was after. It’s working great.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.