- Home /
AssetPostprocessor - OnPostprocess* asset not in the AssetDatabase yet
When I import an AudioClip, I want to create a scriptable object that references the clip (and adds other data as well. The problem if I assign the the clip, it doesn't get serialized properly, presumably because it's not in the AssetDatabase yet.
This results in a null.AssetDatabase.LoadAssetAtPath<AudioClip>(this.assetPath);
Currently I periodically check whether it's there yet and only then I carry on
for (int i = 0; i < 50; i++)
{
clip = AssetDatabase.LoadAssetAtPath<AudioClip>(this.assetPath);
if (clip)
{
break;
}
await Task.Delay(50);
}
This works but feels hacky. Is this a bug or am I missing something? (I'm on 2020.1)
I know this question is from a long while ago, but I'm having this problem now. Were you able to figure it out by chance?
I have switched to a different engine since then actually, so I don't remember. Sorry. I've done a quick search thru my repos and all my code still used smt. like the posted hacky polling snippet, so I don't think I've figured a proper solution/fix. It's been years though, so a newer version of Unity might have fixed it, though seeing you are asking, then maybe not...
Hey thanks anyway for the response. I ended up finding a solution similar to yours, but instead of Task.Delay there's a Unity function that will basically just delay a frame: "EditorApplication.delayCall += () => AssetDatabase.LoadAssetAtPath(this.assetPath)".
I won't list this as an answer, because I'm not sure if this is considered "hacky" as well. But perhaps it'll still be useful if someone else comes across this Question.
Your answer

Follow this Question
Related Questions
Metadata not being saved on custom file types 0 Answers
How do you add extra sub-assets into an asset while importing? 0 Answers
Expandable items in ScriptableObject? 1 Answer
AssetDataBase.ImportAsset not triggering AssetProcessor.PreProcessModel 0 Answers
Prevent OnPostprocessAllAssets being called multiple times 0 Answers