Problem with instantiating/destroying game objects with navmesh cut components attached

So I’ve been experimenting with the scripts for a while now and just come across an odd behavior which i am unsure why it happens.

I have a prefab with navmesh cut component attached. When i place it into my game world, suddenly my recast navmesh disappears entirely. And when i try to move a character on the recast area after adding the prefab, i get this error:

Object reference not set to an instance of an object

The method the error comes from:

public static bool IsPathPossible (GraphNode n1, GraphNode n2)
{
return n1.Walkable && n2.Walkable && n1.Area == n2.Area;
}

So that confirmed to me that the recast graph did just disappear entirely. So i then tried having the navmesh cut component disabled on the prefab to just rule out if this component was the culprit. And found when i now add it to the world - it works perfectly fine.

However, when i destroy the game object even if the navmesh cut component is enabled or disabled, again my recast graph disappears entirely.

I also have a recast graph set for when the object destroys which i thought would solve the problem but it doesn’t seem to work if navmesh cut component is part of the prefab, this is what i have:

void OnDestroy()
{
    mainGO.UpdateGraphBounds(); //a script attatched to the parent of the game object
}

On my MainGO:

 public void UpdateGraphBounds()
{
    Bounds combinedBounds = new Bounds(transform.position, Vector3.zero);
    foreach (Renderer render in GetComponentsInChildren<Renderer>())
    {
        if(render.gameObject.transform.parent.tag == "Player") { continue; }
            combinedBounds.Encapsulate(render.bounds);
    }
    GraphUpdateObject guo = new GraphUpdateObject(combinedBounds);
    guo.updatePhysics = true;
    AstarPath.active.UpdateGraphs(guo);
}

This code works if a prefab has no navmesh cut component attached at all. But if the prefab does, whether enabled or disabled then recast graph seems to cause a crash of some kind on destroy whether or not the navmesh cut is enabled or disabled. Additionally I also call this method when i am instantiating - and this only works if the navmesh cut in first disabled before i initialize.

Also I do have one tile handler helper component attached to my scene.

So currently this is causing a problem for me to progress as i can’t construct my game world at run time due to this problem.

I can send a unity project of the problem if you need to see the behavior in action or perhaps you might know why this happens so i can figure out how to fix it.

Hope you can help :slight_smile:

Hi

Try the latest beta. I think the exception issue should be fixed now.

The recast graph disappears during graph updates because all state might not be valid during the update so it is not necessarily possible to draw the gizmos. It will become visible after the graph update is complete.

For me the gizmos never reappeared. But i will try the latest beta and will let you know how it goes.

Edit:

Seems to be working alright so far - thanks :slight_smile: