Deserializing an ScriptableObject via code.

I have serialized an ScritpableObject to the disk drive. What is the proper way to load the data back into memory via code? I attempted to use the Resources.Load method to load the data. However, it always returns null.

I know that the data was properly serialized, because I can click on the asset file and view the data within the editor. Additionally, I was also able to create a variable within an MonoBehaviour and assign the ScriptableObject asset to it.

The data I created was named 'test.asset' and was placed in the assets folder. When using the Resources object to load the data, my code looks similar to the following:

Object obj = Resources.Load("test"); // I also tried doing test.asset...

In my case, the returned value is always null.

Are you using AssetDatabase.CreateAsset to save your ScriptableObject? It's works fine for me. maybe, if you are using that method to save the asset, you saving it out of the Assets/Resources directory. Try to use:

AssetDatabase.CreateAsset( MyScriptableObjectInstance, "Assets/Resources/test.asset" );

and after:

MyScriptableObject MyScriptableObjectInstance = (MyScriptableObject)Resources.Load("test");

Cheers.