Copy Grid Graph at Runtime

I am creating my intial grid graph just fine. I am trying to copy the current graph to a second graph. I am finding that my second graph is not a clone of the initial graph with respect to walkable state. What might I be doing wrong?

I create the first graph and confirmed it is correct. So now I am trying to copy it to a second graph to maintain its original state. I saw another post where this was a recommendation on how to copy a graph to a second at runtime.

// Copy the main graph to a second graph that will stay unmodified.
var data =;;

// This line cast does not behave the same way as using the linecast on the original graph.
GridGraph secondGraph =[1] as GridGraph;
secondGraph.Linecast(from, to);

Thanks for any assistance.


If you want to copy the whole graph including its nodes, then you need to run SerializeGraphs(new Pathfinding.Serialization.SerializeSettings { nodes = true });, otherwise you will just copy the settings for it.

That was it. I was thinking the default behavior of SerializeGraphs() would serialize the graphs. There must be a good reason that is not the default behavior. Still getting up to speed on the SDK.