Version 4.0: Error when deleting a Layered Grid Graph

Hi.
Just bought the update to version 4 and I’m very satisfied!
I’d like to point out a bug that I came across when creating and then trying to delete a Layered Grid Graph (it’s probably the same thing with normal Grid Graphs but it seems it happens less consistenly).

Step to reproduce:

  • Create a new project
  • Import Astar. I tried with 4.0.6 and with today’s new version, 4.0.7
  • Create 3D object -> plane
  • Create a new empty with the Astar Path component (Pathfinder), of course
  • Create a new Layered Grid Graph, default settings are fine
  • Press “Scan”
  • Try to delete the graph in the component itself.

The graph remains there, and the console outputs this:

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.LevelGridNode.ClearConnections (Boolean alsoReverse) (at Assets/AstarPathfindingProject/Generators/LayerGridGraphGenerator.cs:1036)
Pathfinding.GraphNode.Destroy () (at Assets/AstarPathfindingProject/Core/Nodes/GraphNode.cs:65)
Pathfinding.GridGraph.<DestroyAllNodesInternal>m__0 (Pathfinding.GraphNode node) (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:98)
Pathfinding.LayerGridGraph.GetNodes (System.Action`1 action) (at Assets/AstarPathfindingProject/Generators/LayerGridGraphGenerator.cs:78)
Pathfinding.GridGraph.DestroyAllNodesInternal () (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:92)
Pathfinding.NavGraph.OnDestroy () (at Assets/AstarPathfindingProject/Generators/Base.cs:224)
Pathfinding.GridGraph.OnDestroy () (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:88)
Pathfinding.LayerGridGraph.OnDestroy () (at Assets/AstarPathfindingProject/Generators/LayerGridGraphGenerator.cs:26)
Pathfinding.AstarData.RemoveGraph (Pathfinding.NavGraph graph) (at Assets/AstarPathfindingProject/Core/AstarData.cs:546)
Pathfinding.AstarPathEditor.RemoveGraph (Pathfinding.NavGraph graph) (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:1264)
Pathfinding.AstarPathEditor.DrawGraphHeader (Pathfinding.GraphEditor graphEditor) (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:660)
Pathfinding.AstarPathEditor.DrawGraph (Pathfinding.GraphEditor graphEditor) (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:716)
Pathfinding.AstarPathEditor.DrawMainArea () (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:398)
Pathfinding.AstarPathEditor.OnInspectorGUI () (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:280)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1229)
UnityEditor.DockArea:OnGUI()

After this error, more and different errors come up:

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.GridNodeBase.get_XCoordinateInGrid () (at Assets/AstarPathfindingProject/Generators/NodeClasses/GridNodeBase.cs:49)
Pathfinding.GridGraph.CreateNavmeshSurfaceVisualization (Pathfinding.GridNodeBase[] nodes, Int32 nodeCount, Pathfinding.Util.GraphGizmoHelper helper) (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:1699)
Pathfinding.GridGraph.OnDrawGizmos (Pathfinding.Util.RetainedGizmos gizmos, Boolean drawNodes) (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:1636)
AstarPath.OnDrawGizmos () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:709)
UnityEditor.DockArea:OnGUI()

Most importantly the graph can’t be deleted and I have to reload the scene in order to make it all work again. I tried at runtime, same behavior more or less.

I’m on Unity 5.6.0f3 Personal on Windows 10.

Thanks in advance!
Paolo

Hi

I’m glad you like the update :slight_smile:

Thanks for pointing this out. It was introduced by mistake in version 4.0.6.
I have fixed this in my dev version now and I will likely release an update with the fix later today.