Hi all,
I am trying and save / load a graph generated with the “Recast Graph” type.
Here is the code that I am using to achieve this
`FileInfo fi = new FileInfo(Application.persistentDataPath + relativeGraphDataPath);
if(fi.Exists)
{
Debug.LogWarning ("Loading graphs data from file ");
FileStream fs = new FileStream(Application.persistentDataPath + relativeGraphDataPath, FileMode.Open, FileAccess.Read);
byte[] dataBuffer = new byte[fi.Length];
fs.Read(dataBuffer, 0, (int)fi.Length);//TODO this cast might be dangerous from time to time
fs.Close();
AstarPath.active.astarData.DeserializeGraphs(dataBuffer);
}
else
{
AstarPath.active.Scan();
Debug.LogWarning ("Saving graphs data to file ");
//scan serialize and save the graphs here
Pathfinding.Serialization.SerializeSettings settings = new Pathfinding.Serialization.SerializeSettings();
//Save node info, and output nice JSON
settings.nodes = true;
settings.prettyPrint = true;
byte[] bytes = AstarPath.active.astarData.SerializeGraphs();
FileStream fsw = new FileStream(Application.persistentDataPath + relativeGraphDataPath, FileMode.Create, FileAccess.Write);
fsw.Write(bytes, 0, bytes.Length);
fsw.Close();
}`
This fragment works with Grid Graph but it does not do basically anything with a Recast Graph, in fact when I load it these exceptions are thrown
NavGraph hasn't been generated yet or does not contain any nodes UnityEngine.Debug:LogError(Object) Pathfinding.NavMeshGraph:GetNearest(INavmesh, Node[], Vector3, NNConstraint, Boolean) (at Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs:148) Pathfinding.RecastGraph:GetNearest(Vector3, NNConstraint, Node) (at Assets/AstarPathfindingProject/Generators/RecastGenerator.cs:348) Pathfinding.NavGraph:GetNearest(Vector3, NNConstraint) (at Assets/AstarPathfindingProject/Generators/Base.cs:127) AstarPath:GetNearest(Vector3, NNConstraint, Node) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2531) Pathfinding.ABPath:Prepare() (at Assets/AstarPathfindingProject/Pathfinders/ABPath.cs:163) <CalculatePaths>c__IteratorB:MoveNext() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2383) <CalculatePathsHandler>c__IteratorA:MoveNext() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2270)
and
NavGraph hasn't been generated yet or does not contain any nodes UnityEngine.Debug:LogError(Object) Pathfinding.NavMeshGraph:GetNearest(INavmesh, Node[], Vector3, NNConstraint, Boolean) (at Assets/AstarPathfindingProject/Generators/NavMeshGenerator.cs:148) Pathfinding.RecastGraph:GetNearest(Vector3, NNConstraint, Node) (at Assets/AstarPathfindingProject/Generators/RecastGenerator.cs:348) Pathfinding.NavGraph:GetNearest(Vector3, NNConstraint) (at Assets/AstarPathfindingProject/Generators/Base.cs:127) AstarPath:GetNearest(Vector3, NNConstraint, Node) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2531) Pathfinding.ABPath:Prepare() (at Assets/AstarPathfindingProject/Pathfinders/ABPath.cs:178) <CalculatePaths>c__IteratorB:MoveNext() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2383) <CalculatePathsHandler>c__IteratorA:MoveNext() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2270)
Any suggestion is welcome.
Many thanks.