The exception is: ‘!(o->TestHideFlag(Object::kDontSaveInEditor) && (options & kAllowDontSaveObjectsToBePersistent) == 0)’
Here is my code where I call the AddObjectAsset:
ContentLibrary contentLibrary = target as ContentLibrary;
MyAsset newAsset = null;
if ((Type)anObjectType == typeof(MyAssetTexture))
{
newAsset = ScriptableObject.CreateInstance<MyAssetTexture>();
contentLibrary.Assets.Add(newMyAsset);
}
else if ((Type)anObjectType == typeof(MyAssetText))
{
newAsset = ScriptableObject.CreateInstance<MyAssetText>();
contentLibrary.Assets.Add(newAsset);
}
if( newAsset != null)
{
AssetDatabase.AddObjectToAsset(newAsset,contentLibrary);
}
ContentLibrary is a ScriptableObject with hideFlags = HideFlags.DontSave;
MyAsset is a ScriptableObject with hideFlags = HideFlags.HideAndDontSave;
MyAssetTexture is a subclass of MyAsset
MyAssetText is a subclass of MyAsset
Their flags are defined by the base class MyAsset so hideFlags = HideFlags.HideAndDontSave;
I know this is going to end up being something really silly.
NOTE: I am working with a reordableList, I could not find a way to add asset to the actual reordablelist. So I intercepted the click method and added the object directly to the instances list (Assets)…
So on the editor it seems to be drawing the base class MyAsset with nothing in it (an empty element) and on top of it the actual derived class MyAssetTexture or MyAssetTex with the correct drawing as defined by a ContentLibraryEditor class.
No idea if there is a relation to the problem or not.