Create a scriptable object as an asset and then load it
Hello everybody,
For a script, I need to create a scriptable object and then load it, unfortunately it doesn't work. Here is what I use :
//To create the scriptable object (and it works)
MyScriptableObjectClass asset = ScriptableObject.CreateInstance<MyScriptableObjectClass>();
AssetDatabase.CreateAsset(asset, "Resources/mySO");
AssetDatabase.SaveAssets();
//To load the scriptable object
anOtherScriptableObject = Resources.Load< MyScriptableObjectClass>("mySO");
It seems that there is a delay between the time the Scriptable Object is create and the time where I can load it.
Does someone have an idea ?
Regards
Answer by LeonmFF · Oct 24, 2019 at 03:17 PM
I'm not sure what's happening here, in my case I created my SO with a custom inspector at design time. But if you think the timing is the problem, call you Load in a Coroutine after waiting some time.
Answer by Magnificent_7 · Oct 24, 2019 at 09:10 PM
Thank you,
that's what I wanted to do but since I am doing it at import (using the AssetPostProcessor class of the UnityEditor library), the function that create the SO is a static one and it seems that you can't start a coroutine in a static function.
Your answer
Follow this Question
Related Questions
How can I load an custom file from the Assets folder? 1 Answer
SetDirty won't work on Nested List 1 Answer
Creating a ScriptableObject instance of a Created Asset 1 Answer
Including Scriptable Object Asset Menu in Inspector? 0 Answers
Resources.Load not loading instances of a scriptableObject 0 Answers