AssetDatabase.MoveAsset doesn't move assets?

I try to move a bulk of assets from one folder into an existing sub-folder, but it doesn’t seem to work. In the following, I post my code to move the assets. I replaced some constants with literals for readability, some some arguments might look a little weird.

        string[] guid = AssetDatabase.FindAssets("*Statistics.asset", new string[] { "Assets/Generator/Statistics" });
        for (int index = 0; index < guid.Length; index++)
        {
            string oldPath = AssetDatabase.GUIDToAssetPath(guid[index]);

            TrackSectionStatistic asset = AssetDatabase.LoadAssetAtPath(oldPath, typeof(TrackSectionStatistic)) as TrackSectionStatistic;

            string newPath = string.Concat("Assets/Generator/Statistics", "/Archive/", asset.name, ".asset");
            if (string.IsNullOrEmpty(AssetDatabase.ValidateMoveAsset(oldPath, newPath))) {
                AssetDatabase.MoveAsset(oldPath, newPath);
            } else
            {
                Debug.Log($"Failed to move asset from path '{oldPath}' to '{newPath}'.");
            }
        }

Interestingly, in the final if-statement, neither of the two cases logs anything to the console ( only one is present in this code snippet). I use a EditorCoroutine to perform this action, maybe that is why nothing appears to work with the assets? Or can’t I move an asset which is loaded with AssetDatabase.LoadAssetAtPath()?

Have you refreshed your database after moving the files?

1 Like

Thank you, that solved the issue!