Support Forum

Growing empty array entries when using DeserializeGraphsPartAdditive

Hi all,
I’m currently integrating the Pathfinding Project into my project and it’s working great so far! :slight_smile:
Because I’m loading my Scenes additively in Unity I have one MainScene that contains my Pathfinding Component and whenever a new Scene is loaded I’m deserializing a “Blueprint” GridGraph and then update the bounds of it to match the newly loaded level.
This is my code that is executed when a new Scene is loaded:;

GridGraph newGraph = (GridGraph)
    graph => graph is { name: "Graph Blueprint" }
); = level.LevelId.StringValue;
); = level.LevelPosition + (level.LevelSize / 2F);


When a Scene is unloaded I remove the Graph like this

foreach (NavGraph graph in
    if (graph == null || != continue;;

Functionally this works like a charm, however DeserializeGraphsAdditive always creates a new entry in the graphs array, while RemoveGraph only nulls and does not remove it from the array.
This causes the graph array to get bigger with every level load and I’m currently trying to find the best solution for that.

The most straight forward solution for me would be to make DeserializeGraphsAdditive also check for empty array indexes. That would be consistent with how AddGraph does it. But of course the might be good reasons for why it is not doing that.

Alternatively I could rebuild the graphs array myself after adding/removing an entry, for example by creating a new array without empty entries and then replacing it with the graph-array.
However this would cause all graph indexes to potentially be reordered and I’m not sure what the implications of that would be.
Would love to get another opinion on this :slight_smile: