Issue with loading scriptable objects at runtime

NOTE: This issue I’m talking about is only on Unity 5.x, forgot to mention that in title.

Already fixed this, but I thought I’d post here just in case anyone runs into similar problems. I had a scriptable object saved to disk as an .asset file in my Resources folder. My script (that worked in Unity 4.x) is supposed to load the scriptable object from disk at runtime and store the type of the script in a singleton. However, in Unity 5 the Resources.Load function would keep returning null… but only on an Android build (it worked fine in editor). Here was the old code that doesn’t work:

instance = Resources.Load<PluginDatabase>("PluginDatabase/" + SAVE_FILENAME);

When I changed it to this, it now works both in editor and on an Android build:

instance = (PluginDatabase)Resources.Load("PluginDatabase/" + SAVE_FILENAME, typeof(PluginDatabase));

Should not both methods produce the exact same result (preferably the result that doesn’t break my code)? I feel this is worthy of a bug report.

Smells like a bug to me… We are only using the generic version of all methods, and we never encountered any issue with loading resources… What is the actual path to your file ?

Assets/Plugins/Resources/PluginDatabase/PluginDatabase.asset

However, it’s very possible that there was a unrelated bug in my code that was throwing an exception that occurred before the asset was loaded from resources, which could result in the asset loading not occurring, thus resulting in the instance being null. If you’re not having any issues with the generic methods then it’s quite possible this may not be a bug at all. I’ll look more into it.

1 Like

Yes we are not having any issues at all :slight_smile: Make sure to drop the .asset file extension (you load the object using its name only).