Still able to get GUID with path (and vice versa) after AssetDatabase.Delete()

Hello, Dear Forum,

I cannot understand why but after the deletion of an asset with AssetDatabase.Delete(string path) I’m still able to get the asset GUID with an asset path, and vice versa.

My only guess is that the GUID mapping is stored in memory, and for some reason, it’s not updated once the file is deleted with AssetDatabase.Delete() function.

I tried to use AssetDatabase.ImportAsset(ImportAssetOptions options) with all available options, AssetDatabase.SaveAssets() and AssetDatabase.Refresh(), but had no luck.

I guess AssetDatabase.ForceReserializeAssets() function could help here, but it’s available starting from Unity 2017.4, while in our project we use Unity 2017.2 where this function doesn’t exist yet.

The only uncomfortable solution which I found is to re-open the whole project, but it’s not the solution in our case since we want to automate some crucial part of our operations with files. Also, we could use System.IO.File.Delete() but I wouldn’t like to do that until I understand why the Unity-implemented functions work strangely or what I’m missing.

So, what should I do after the use of AssetDatabase.Delete() to update the out-of-date GUID mapping or any other deprecated information used by Unity?

I will be very thankful for any help.

Regards,
John.

I don’t have the solution, but for a temporary fix you could have a wrapper function for both getting the GUID and vice versa, but also including a check to see if that asset is actually there. Not the best, I know

You might have to refresh the database after deleting the file. Keep in mind this could take a while.