GetGridGraph returns null

Hi all. I’ve recently run into an issue with grid graphs. I had just updated to Unity 5.5 and the latest A*.

The issue seems to occur after I’ve cleared a scene that had multiple Grid Graphs. I can add a new graph to the scene just fine, but then I run into issues with

Specifically, these lines in GridNode.cs:

GridGraph gg = GetGridGraph(GraphIndex);  < will return a null gg because:

    public static GridGraph GetGridGraph (uint graphIndex) { return _gridGraphs[(int)graphIndex]; }

It’s being passed a graphIndex of a null Gridgraph. It’s as if an index remains from the previously cleared gridgraphs, which are now null. I haven’t had any problems with this in the last six months, so I’m not sure what to do about it now. I suppose I can just write an index check, but I wanted to make sure something else wasn’t wrong, or if this was a new bug. Thanks.

Further poking around suggests that RemoveGraph(graph) isn’t properly destroying/clearing the graph array.

Edit: Reverting back to 3.8.1 fixed the issue. Thankfully that version seems to play nice with Unity 5.5, but I’m worried when it comes time to upgrade. Any fixes or advice would be appreciated, thanks.


Could you elaborate on what the issue is with RemoveGraph?
I checked the code for that method but I cannot see anything obviously wrong with it.

Maybe it is related to this bug?

Sorry I can’t debug since I’ve reverted, but that does sound possible. Last time I checked, I should have had two active gridgraphs, but the _gridGraphs length was 5. Items 2, 3, and 4 were null. Not sure if this is normal behavior. My assumption is that none of these should be null, or the array length set to 2, but I could be wrong.

The _gridGraphs array may be larger than the number of graphs that have been loaded, however if you have loaded N grid graphs then only N elements in that array should be non-null.