- Home /
When a gameobject is destroyed a chunk of the navmesh gets destroyed
I came across a problem during runtime with a baked navmesh. I have a gameobject with navmesh obsticals set to carve when stationary. This gameobject moves up through the map and stops until a button is pressed then it goes through the bottom of the map and gets destroyed. Sometimes when the gameobject gets destroyed it also takes a huge chunk of the navmesh with it, this causes nav mesh agents to teleport to whatever is left of the navmesh. Its weird but it seems to only happen if the gameobject gets destroyed. I was wondering if anyone has seen this problem before or if anyone can help me figure out why this is happening. I have a picture of the navmesh after a chunk is taken from it when the gameobject is destroyed. Thanks!
I think re check your code and make sure your Navmesh object is not destroying due o other script and make sure that destroying script is not attached on any Navmesh agents. Its possible the object you are destroying is the parent of the Navmesh.
So if the object is being destroyed from another script it can do this sort of thing? Should I always try to avoid destroying a gameobject with another script that's not on the gameobject? Is there anything else that could cause this and is there a way I could check if the gameobject is a parent of the navmesh? Thanks!
Answer by Kurt5 · Jul 20, 2017 at 12:31 AM
Try deleting the object one frame after disabling the carving/obstacle as it takes one frame after disabling carving for the NavMesh to change back. Still not sure why it's deleting the NavMesh permanently like that though.
https://docs.unity3d.com/Manual/class-NavMeshObstacle.html
"Note: When using NavMesh query methods, you should take into account that there is a one-frame delay between changing a Nav Mesh Obstacle and the effect that change has on the NavMesh."
Answer by DJGhostViper · Jul 19, 2017 at 11:31 PM
As of right now the only solution ive found is to disable the nav mesh obstical right before the object is deleted, deleting the active nav mesh obstical with the gameobject at the same time causes the chunk of navmesh to vanish.
Your answer