- Home /
How to access ScriptableObject during initial import pre-process?
For my project I have created a custom asset importer (descendant of AssetPostprocessor) that utilizes data stored in a ScriptableObject, such as folders that would be used to identify certain import options. The problem I am seeing is that I am unable to correctly instantiate the ScriptableObject from the asset during a preprocess function (e.g. OnPreprocessTexture()) on an initial import, that is when the project is first retrieve from source control or if the Library file is deleted.
In other words the following code doesn't return the ScriptableObject reference on initial import but does on subsequent imports, in both cases I am sure the asset file exists.
private T InstanceGetData<T>() where T: ScriptableObject
{
string settingPath = SETTINGS_ASSET_PATH + typeof(T).Name + ".asset";
//This will not work during an initial import
T data = AssetDatabase.LoadAssetAtPath(settingPath, typeof(T)) as T;
if (data == null)
{
Debug.LogError(typeof(T).ToString() + " not defined");
}
return data;
}
Is there some other way to get a ScriptableObject reference from the asset at this point, other than writing a custom deserialier? Or, is there a way to get the editor to complete import of my scriptable objects before beginning the import of other assets?
Your answer
![](https://koobas.hobune.stream/wayback/20220611234717im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unable to assign array data on scriptable object 2 Answers
How can I make a text file immediately appear in my project from an AssetPostProcessor script? 1 Answer
Can you make an EditorWindow pop up and block the asset import process while it's open? 0 Answers
is it possible to have a global/static variable in the AssetPostprocessor script 1 Answer