News › Forums › RAIN › General Discussion and Troubleshooting › Can't reset Navigation Mesh during runtime
Tagged: AI, generating, navMesh, runtime
This topic contains 3 replies, has 2 voices, and was last updated by BlueOctave 6 months, 2 weeks ago.
-
AuthorPosts
-
January 22, 2023 at 8:38 pm #39943
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.
January 22, 2023 at 11:45 pm #39946You 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.
January 24, 2023 at 6:38 pm #39950Thank you for the response, I am glad you guys are still actively working on this AI system, it really is the best.
January 24, 2023 at 6:49 pm #39951Problem 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.
-
AuthorPosts
You must be logged in to reply to this topic.