No graph loaded from cache if AStarPath component selected when entering play mode (5.0.3)

Hello,

I have a AStarPath component with a single GridGraph using version 5.0.3.

I am using “Generate Cache” to rescan the graph and save it to a file. I was finding that entering play mode was having an empty graph.

I thought this was an issue with the graph cache file not updating correctly so I added scripts to ensure it’s checked out with version control, to manually call AssetDatabase.SaveProject, AssetDatabase.ImportAsset(pathToCache), AssetDatabase.Refresh etc but none of these steps actually helped.

I found selecting the file worked, so I added something to force it selected. However I wanted to return selection to the AStarPath object to not confuse the person working with the tool and I found the issue came back.

I’ve now got a new fix for the Editor - when exiting edit mode, if an AStarPath component is selected I wipe the selection of the user. This works.

Is this a bug that can be fixed either through an update or a config change I can use on my end? I’ve got ScanOnAwake disabled. Happy to share any other info which can be helpful where I am able.

Here is my code for my workaround for anyone that needs it.

Thanks!

[InitializeOnLoad]
    public static class CacheGraphEditorFixEnterPlay {
        static CacheGraphEditorFixEnterPlay() {
            EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
            EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
        }

        private static void OnPlayModeStateChanged(PlayModeStateChange state) {
            if(state == PlayModeStateChange.ExitingEditMode) {
                bool isSelectingPath = false;
                foreach(Object selectedObject in Selection.objects) {
                    if(selectedObject is GameObject gameObject && gameObject.GetComponent<AstarPath>() != null) {
                        isSelectingPath = true;
                        break;
                    }
                }
                if(isSelectingPath) {
                    Selection.activeObject = null;
                }
            }
        }
    }