"Asset is not persistent" Editor Error

Hello :slight_smile:

I have a ScriptableObject that contains a list of other ScriptableObjects (sub-assets). My main ScriptableObject asset is created through the Create menu in the editor (I’m using the new 5.1 [CreateAssetMenu] attribute). My sub-assets are added via a button on a custom inspector on the main asset. When the button is pushed, those code runs:

MySubAsset subAsset = ScriptableObject.CreateInstance<MySubAsset>();
AssetDatabase.AddObjectToAsset( subAsset, myMainAsset );

I watched the serialization talk by @Tim-C and grabbed the above code from that.

It seems like it should work, but when I hit the button to add a sub-asset, I’m getting the following errors:

What on earth does that “AddAssetToSameFile failed because the other asset is not persistent” error mean? O_O I haven’t seen that error referenced anywhere else on the forums or Unity Answers :frowning:

Any insight would be appreciated!! <3 :slight_smile:

Cheers!

  1. I just realized I posted this in the Scripting forum instead of the Editor forum. Whoops! :sweat_smile:

  2. I figured out the issue! I was trying to add a sub-asset to a sub-asset, which apparently Unity doesn’t like :slight_smile: So now I’m adding the sub-sub-asset to the main asset, but maintaining a separate list of sub-sub-assets in the sub-asset :face_with_spiral_eyes::smile:

4 Likes