News › Forums › RAIN › General Discussion and Troubleshooting › How to dynamically create the NavMesh
Tagged: dynamic navmesh
This topic contains 5 replies, has 3 voices, and was last updated by GlennNZ 2 years ago.
-
AuthorPosts
-
April 18, 2022 at 9:09 am #12225
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?
April 21, 2022 at 10:01 pm #12415I 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.
April 21, 2022 at 10:30 pm #12418I 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.”
May 5, 2022 at 4:58 pm #13381Here 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!
May 5, 2022 at 9:05 pm #13394Right on Philo, thanks for bringing this back to GlennNZ! Now that’s a real community effort!
May 6, 2022 at 8:11 am #13436Thanks guys. Yes, that 5th May reply by philio in the above linked thread is indeed the solution I was after. It’s working great.
-
AuthorPosts
You must be logged in to reply to this topic.