Hi, I was having an issue with saving and loading Scriptable Objects of my projects.
My scriptable objects have something like:
Code: Select all
public class MyScriptableObject : ScriptableObject
{
string itemName;
Sprite itemImage;
GameObject prefab;
float damage;
float cost;
}
of these, string and float appear just fine when I call ES3.Load<MyScriptableObject>, but sprite and GameObject are lost. (itemName and prefab, in the above example). But the scriptable object asset in the project folder itself did not lose any of its data during saving/loading. Considering that the said loaded scriptable objects has no name at all, it appears to be a copy of incomplete asset.
Looking through old posts on the forum, I believe the issue that I am saving the scriptable object by reference, not by its value. I've been saving like:
Code: Select all
ES3.Save<MyScriptableObject>("SAVE", transform.GetComponentInChildren<Item>().MyScriptableObject);
The above code is causing the issue, so I tried making a new array of MyScriptableObject, or creating a new MyScriptableObject and then assigning them. I also tried putting [ES3Serializable] on every possible variables on the SO. But none of the ways in which I attempted to find MyScriptableObject's value worked, and only found its reference.
How do you properly save scriptable object as an asset, and not save an instance of the scriptable object that's created during runtime? Or, was I getting all of those things wrong? Please let me know, thanks.