Clearing Graph Cache Via Script

Hello,

I’m currently creating a randomly generated dungeon game and using the grid graph method to create a pathfinding map. I create the grid graph at runtime and have a question.

When I update I usually get the message “Trying to load data from an older version of the A* Pathfinding Project” even though I don’t want to save data and also are calling AstarPath.active.astarData.cacheStartup = false when I create the graph. I assume some sort of cached data ie being stored. I have even clicked the “clear cache” button in game, but this is still happening. Is there a way to clear all sorted graph data via script?

Also, is there a simple way if enabling the optimisation settings via script as well?

Hi

Hm. Odd, so in the Save & Load tab in the editor (not when playing) there is nothing that says that a cache is stored?

When you say you are creating a graph during runtime, are you using something like AstarPath.active.astarData.AddGraph(…) or do you mean something else?

Optimization settings cannot be changed during runtime because they are changes to the compiler directives, so after the code has been compiled, they cannot be changed. See https://msdn.microsoft.com/en-us/library/4y6tbswk.aspx

Save node data is ticked, but there is nothing inside the box under “Cache startup”.

I generated the node data by running:

	AstarData data = AstarPath.active.astarData;
	data.cacheStartup = false;
	GridGraph gridGraph = data.AddGraph(typeof(GridGraph)) as GridGraph;

I then update all the parameters I need and then call.

	gridGraph.UpdateSizeFromWidthDepth();

As for the optimisation, seeing as I don’t have a graph object in the scene, I cannot fiddle with the optimised settings. Is it best I just have a blank A-Star Path GameObject which I populate when the level starts so I can then manually check and uncheck optimised settings? Finally, what optimisations are recommended for a 2d grid graph I generate at runtime?

Yeah, this worked. I don’t know why I need to write 20 characters, so I’m writing this sentence too.

Is it best I just have a blank A-Star Path GameObject which I populate when the level starts so I can then manually check and uncheck optimised settings? Finally, what optimisations are recommended for a 2d grid graph I generate at runtime?

Yeah, that works fine.
You can turn off custom grid graph connections to save some memory, but other than that there is not that much to do.

Also, don’t forgot to call AstarPath.active.Scan after you have added your graph so that it is calculated (maybe you are already doing that and just left it out of the post).