- Home /
AssetDatabase.AddToObject with existing assets
Hi, i have a huge amount of .asset files (ScriptableObject derived classes) that i now want to add to a collection (another scriptableobject derived class as .asset) to get rid of all the separate files (i want to be able to delete them after adding them to the collection).
Before i break things i wanted to ask this to be sure. Can i use the AssetDatabase.AddObjectToAsset() with existing assets (the asset to add to the collection), or do i maybe have to instantiate that first to make it work or something like that?
Edit: i want to maintain the references to these objects if possible after they've been added to the asset.
I'm curious about this too, but I think experimenting with it on a test project might be the fastest way to find out.
Answer by Polymo · Sep 11, 2015 at 04:35 PM
if i instantiate it that would obviously create a new object, so the reference to it is not maintained, so what are my options?
Ok, it looks like it can't be done in a simple way. I ended up testing a mix of EditorUtility.CollectDependencies and Reflection with FieldInfo and GetValue comparison and SetValue with new instances through EditorUtility.CopySerialized which seems to work (in the test project).