- Home /
Removing invalid objects under asset
I've created a simple structure of a ScriptableObject containing other ScriptableObjects with the use of AssetDatabase.AddObjectToAsset.
This works perfectly, but now I've encountered a situation where I renamed and or removed one of my child ScriptableObjects thus resulting in an asset with an unvalid (null) script.
I have a CustomEditor for the parent (root) ScriptableObject, and I thought that would be the prefect place to clear any child object thats no longer valid. The problem is, I can't figure out how.
I'm able to list all assets (includning the invalid one) with the use of AssetDatabase.LoadAllAssetsAtPath, but then I encounter a problem trying to use AssetDatabase.DeleteAsset or AssetDatabase.RemoveObjectFromAsset, since there is no actual object for me to pass along (it's null).
How can I clear out any invalid (null) child objects that was previously added to an asset? Thanks!
@PatrikL Same issue here. Did you find a solution?
Hi, I use the same kind of data structure; Looking at the .asset file itself, it seems quite clear what section of this text file correspond to what serialised sub-scriptable object (with Unity Editor settings set to use text files, not binary). It's possible to edit the files with a text editor or develop a text parsing script. Not ideal, but should work :-)