News Forums RAIN General Discussion and Troubleshooting Can't reset Navigation Mesh during runtime

This topic contains 3 replies, has 2 voices, and was last updated by  BlueOctave 6 months, 2 weeks ago.

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

    BlueOctave
    Participant

    So I am trying to reset the navigation mesh when you click on a button. This works great the first time, but after that, if there is a new object in the way and you try to refresh the navigation mesh, the entities completely ignore it. The mesh in the editor is showing that the mesh DID update, but the entities don’t care.

    Is there a quick way around this or do I have to create a completely new navigation mesh each time I run the script?

    Code:

    public void GenerateNavmesh()
        {
            NavMeshRig navMesh = this.GetComponent<NavMeshRig>();
            navMesh.NavMesh.ClearNavigationGraph();
            navMesh.NavMesh.Reset(navMesh);
            navMesh.NavMesh.UnregisterNavigationGraph();
            navMesh.NavMesh.StartCreatingContours(4);
            while (navMesh.NavMesh.Creating)
            {
                navMesh.NavMesh.CreateContours();
                Thread.Sleep(10);
            }
            navMesh.NavMesh.RegisterNavigationGraph();
        }
    • This topic was modified 6 months, 2 weeks ago by  BlueOctave.
    #39946

    Sigil
    Keymaster

    You are trying to refresh the navmesh while the game is running right? There is a bug in the BasicNavigator right now that stops the AI from picking up newly generated navigation meshes. The simple way around it is to set the CurrentGraph property to null on any AI that might be affected (forcing a repath):

    AIRig tRig = GetComponentInChildren<AIRig>();
    tRig.AI.Navigator.CurrentGraph = null;

    There will be a fix for this in the next version of RAIN so that the AI automatically repath if the graph gets regenerated.

    #39950

    BlueOctave
    Participant

    Thank you for the response, I am glad you guys are still actively working on this AI system, it really is the best.

    #39951

    BlueOctave
    Participant

    Problem solved, meant to delete this post.

    • This reply was modified 6 months, 2 weeks ago by  BlueOctave.
    • This reply was modified 6 months, 2 weeks ago by  BlueOctave.
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.