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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12670

    philo
    Participant

    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();
    #13301

    philo
    Participant

    Bump.

    Any help on equivalent functions in the new API would be much appreciated.

    #13307

    CodersExpo
    Participant

    I’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.
    #13380

    philo
    Participant

    Excellent. 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();
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.