- Home /
Load an asset right as it is imported?
Heyo!
Alright, so I'm working on an asset that people will be able to import into their project. To keep my question simple, I'll only mention the important parts. I have a script that is using [InitializeOnLoad] so that whenever the code is compiled (and it is compiled as it is added to the project), a function will run. This function looks into the folder that was JUST imported, finds a texture in one of the child folders (using AssetDatabase.LoadAssetAtPath), and saves it in a static variable.
So, my issue is that when the package is first imported, this function can't quite find the texture because that texture JUST got imported. I've tried using AssetDatabase.Refresh and AssetDatabase.ImportAsset and neither seem to solve the issue. Is there an easy way to grab the texture right after it was imported?
If there is no nice solution, I probably can use EditorApplication.update += Update
to keep searching for the asset until it is properly found. That would probably work I guess? Just wondering if there is a cleaner way.