Hi !!
Today I faced a quite strange problem related with ScriptableObjects, I’m doing an inventory tool that handles the objects created, assigning different types to them etc…
Here I have the basic data of the Objects :
namespace Inventory
{
[System.Serializable]
public class ObjectInventory
{
[SerializeField]
public TYPE_OBJECT_INVENTORY type_object;
[SerializeField]
public string name_object;
[SerializeField]
public string description;
[SerializeField]
public Sprite object_icon;
[SerializeField]
public bool is_stackable;
[SerializeField]
public int max_capacity;
[SerializeField]
public GameObject go_picked;
[SerializeField]
public string name_script_obj;
}
}
Then I have my Asset who derives from ScriptableObject:
[System.Serializable]
public class ObjectAsset : ScriptableObject
{
[SerializeField]
public ObjectInventory obj;
}
And Finally one derived class from ObjectInventory that only keeps one GameObject.
namespace Inventory
{
[System.Serializable]
public class ToolObjectInventory : ObjectInventory
{
[SerializeField]
public GameObject tool_object;
}
}
Everything works fine, in the editor, if I know that I’m creating a Type of object that is a tool I jus simply do the following:
new_asset = ScriptableObject.CreateInstance<ObjectAsset>();
new_asset.obj = new ToolObjectInventory();
And I can modify the class values and everithing, the problem comes when I hit the Play Button, the type of the object saved in the ObjectAsset just changes to ObjectInventory, the Base class, loosing all the information saved previously.
I used AssetDataBase.Save and SetDirty() to save all the data and the rest of the information like names,icons,descriptions etc is saved correctly.
Please if somebody would give some hint about what’s happening I would be really grateful.
THANKS.!