News › Forums › RAIN › General Discussion and Troubleshooting › Programatic Navmesh Generation in 2.0.11
This topic contains 3 replies, has 2 voices, and was last updated by philo 2 years, 10 months ago.
-
AuthorPosts
-
April 24, 2022 at 9:21 pm #12670
Hi,
I’ve previously been using the code below to auto generate the Navmash when first loading a scene and it worked fine. However, after updating to 2.0.11 I can’t compile. The API no longer lists some of the methods so I assume something has changed, but I can’t see any indication of what the new methods are. Any advice?
RAIN.Navigation.NavMesh.NavMeshRig rig = GameObject.FindGameObjectWithTag("NavMesh").GetComponent<RAIN.Navigation.NavMesh.NavMeshRig>(); RAIN.Navigation.NavMesh.NavMesh mesh = rig.NavMesh; //clear the existing navmesh mesh.ResetGraph(); //start building the new navmesh mesh.StartCollectingColliders(rig); mesh.CollectAllColliders(); mesh.StartCreatingContours(rig); while (mesh.Creating) { mesh.CreateContours(); System.Threading.Thread.Sleep(10); } mesh.GenerateNavMeshGraph();
May 4, 2022 at 2:38 pm #13301Bump.
Any help on equivalent functions in the new API would be much appreciated.
May 4, 2022 at 5:08 pm #13307I’m not a 100% on what you’re after, but it looks like you’re creating a mesh graph based on the navigation rig component settings. So, your question on how to clear the mesh graph is done using rigMesh.StartCreatingContours(rig, 1);
However, be sure to unregister —create—-and register the navigation graph with the path graph manager.
var gameObject = GameObject.FindGameObjectWithTag(“NavMesh”);
if(gameObject != null)
{
var rig = gameObject.GetComponentInChildren<RAIN.Navigation.NavMesh.NavMeshRig>();if(rig != null)
{
var rigMesh = rig.NavMesh;if(rigMesh != null)
{
Debug.Log(“Got the mesh ” + rigMesh.Name);//Navigation graph name
}rigMesh.UnregisterNavigationGraph();
rigMesh.StartCreatingContours(rig, 1);//This will create a new mesh path graph based on the navigation rig settings
//rigMesh.StartCreatingContours(new Vector3(0,0,0), new Vector3(3f,1f,3f), 1);//Create new scale and position. You can access other settings on the rig to change as well.
while (rigMesh.Creating)
{
Debug.Log(“Is creating…”);
rigMesh.CreateContours();
System.Threading.Thread.Sleep(10);
}
rigMesh.GenerateAllContourVisuals();rigMesh.RegisterNavigationGraph();
}
}Hope this helps…
Also, note this is just straight code in CustomAction. You can also create custom NavigationMesh to select in the rig. This will allow you to override certain methods as needed.
- This reply was modified 2 years, 10 months ago by CodersExpo.
May 5, 2022 at 4:54 pm #13380Excellent. That worked brilliantly. Looks like it’s exactly the same logic as what I had previously, but just different naming (UnregisterNavigationGraph instead of ResetGraph etc).
For reference, the final code is:
RAIN.Navigation.NavMesh.NavMeshRig rig = GameObject.FindGameObjectWithTag("NavMesh").GetComponent<RAIN.Navigation.NavMesh.NavMeshRig>(); RAIN.Navigation.NavMesh.NavMesh mesh = rig.NavMesh; //clear the existing navmesh mesh.UnregisterNavigationGraph(); mesh.StartCreatingContours(rig, 1); while(mesh.Creating) { mesh.CreateContours(); System.Threading.Thread.Sleep(10); } mesh.GenerateAllContourVisuals(); mesh.RegisterNavigationGraph();
-
AuthorPosts
You must be logged in to reply to this topic.