I want to do a batch processing of the scenes I have to enable the cache graph data and node data and then set some couple of options. Then I want to save the scene with different name , preserving my original scene.
Now, I had look at the editor script for the AstarPathEditor and I was hoping I could do the following :
Open scene
Do the following to set up the scene and cache the data
I have serializationSettings decleared exactly the same way as the editor script :
public static Pathfinding.Serialization.SerializeSettings serializationSettings = Pathfinding.Serialization.SerializeSettings.All;
Save as other name and repeat for other scenes.
All of above using editor script and process them in editor mode. (Not in play mode)
But then I get null reference on AstarPath.active.astarData.cacheStartup = true;
All of the scenes do contain a game object with AstarPath script attached to it and all other settings are manually adjusted in. Strange thing is if I do call above script process manually after I have opened up the scene , it works fine. But not when I use script to open the scene and then call the bathing process script right after it.
I am wondering if it needs any time to cache in active path in AstarPath ?
Well, it seems that it doesn’t actually scan the graph properly after all… If I use editor to generate cache I should get 23.5kb but when I used API call it only gets like 450 bytes.
Yes, I have missed doing AstarPath.active.astarData.DeserializeGraphs();
Well, I don’t know what that does, but it seems to work now… so in order to scan the graph and cache in, I need to do the DeserializeGraphs() and Scan() ?
Well, you seem to have solved this all by yourself.
The reason you need to set AstarPath.active is that there is no code that has initialized the singleton pattern yet (as you noted).
The reason you need to call DeserializeGraphs is that since the AstarPath object has not really been initialized, the graphs are just stored in a byte array and the AstarPath object thinks it has no graphs added, calling DeserializeGraphs will load them.