Saving Settings in Editor

I’ve written a script to update certain settings in all of the graphs in our game. But I can’t figure out how to force A* to save the settings.

Here’s the script:

        [MenuItem("Assets/Voodoo Helpers/Multi-scene Pathfinder Update")]
        public static void UpdatePathfinders()
        {
            // string originalPath = EditorSceneManager.GetActiveScene().path;
            foreach (EditorBuildSettingsScene sceneId in EditorBuildSettings.scenes)
            {
                Scene scene = EditorSceneManager.OpenScene(sceneId.path, OpenSceneMode.Single);
                AstarPath.FindAstarPath();
                if (AstarPath.active != null)
                {
                    GridGraph graph = AstarPath.active.data.gridGraph;
                    if (graph != null)
                    {
                        Debug.Log("Updating Pathfinder in Scene: " + scene.name);
                        graph.erodeIterations = 1;
                        graph.erosionUseTags = true;
                        graph.erosionFirstTag = 1; // First Tag
                        EditorUtility.SetDirty(AstarPath.active);
                        // AstarPathEditor.SaveGraphs(); ????

                        Debug.Log("SAVE SUCCESS" + EditorSceneManager.SaveScene(scene));
                        break;
                    }
                }
            }

            // // Return to Original Scene
            // EditorSceneManager.OpenScene(originalPath, OpenSceneMode.Single);
        }

Can someone explain how to save changes made via script in editor?

Anyone know how to do this?

var data = AstarPath.active.data;
data.SetData(data.SerializeGraphs(Pathfinding.Serialization.SerializeSettings.Settings));

should do it.

1 Like