0
\$\begingroup\$

I have a ScriptedImporter that generates a few extra assets, this works fine except when I re-import it after version upgrade, I get the following message:

Asset with guid 'bbe94cef9d5f3464ab6ba6913e6747a2' and path '...' is up to date, but does not have a correct target hash assigned to it in the GuidPersistentManager
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

Inside that ScriptedImporter I've tried File.Delete, AssetDatabase.Refresh, AssetDatabase.ImportAsset but neither helped out, only when I delete it manually it does work.

Furthermore, that error message is quite useless as basically Unity handles it but still notifies you.

Note that the asset generated is next to the format being imported, this is because if for instance you create a texture and add it to the AssetImportContext then it becomes readonly in the Inspector and cannot be tweaked further. So basically I generate a PNG file in same folder which then has the usual TextureImporter that can be edited as will.

Question:

How to avoid incorrect GUID errors when re-importing an asset generated by a ScriptedImporter?

Alternatively, how to solve this incorrect GUID clash when overwriting an asset?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

That pseudo code works somewhat but is slow, this is when the asset exists and you want to avoid that error by updating its:

RemoveContentFromAsset(asset); // AssetDatabase.RemoveObjectFromAsset recursive
EditorUtility.CopySerialized(track, asset);
AddContentToAsset(asset); // AssetDatabase.AddObjectToAsset recursive
AssetDatabase.SaveAssets();
// this will refresh project browser and fix empty sub asset editor but is slow
// EditorUtility.RequestScriptReload(); // stupid project browser won't refresh view otherwise

But I've opted this way instead:

How to avoid many import iterations while generating sub assets?

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .