- Home /
Destroying unused child subassets
Hey guys,
So, long story short, I have a list of scriptable objects which have been added as subassets to a gameobject. And a while back, while I was mucking around with making it work, I accidentally ended up with ALOT of subassets attached to some prefabs. (And till now, I still keep getting leftover subassets which don't actually exist in the list)
So... Can someone please tell me how to get rid of all the unused child assets of a game object? Like, these ones:
For instance, in this case, Player actually only has like 4 of the scriptable objects in the list, but you can see that there are MANY leftover scriptable objects from changing around the list stuff.
What's with dragging it into the hiearchy, removing them there and applying the Prefab again?
Well, it doesn't appear when i drag it into the hierachy, since it only exists in the prefab. (like, if i drag the Player prefab into the hierachy, it'll actually have no children there).
Answer by Bunny83 · Jul 05, 2017 at 02:38 PM
First i wouldn't recomment to add other assets to "prefab assets". It's ok to add multiple assets to a generic ".asset" asset.
Though there are several ways how to remove such assets. First you can try an editor script like this:
//DestroyObjectsEditorWindow.cs
using UnityEditor;
using System.Collections.Generic;
public class DestroyObjectsEditorWindow : ScriptableWizard
{
public List<UnityEngine.Object> objects;
[MenuItem("Tools/DestroyObjects")]
static void CreateWizard()
{
DisplayWizard<DestroyObjectsEditorWindow>("Destroy Objects", "Destroy");
}
void OnWizardCreate()
{
if (EditorUtility.DisplayDialog("Destroy Objects", "Are you sure you want to destroy those objects?", "yes, i'm sure", "the hell, no"))
{
foreach (var obj in objects)
{
DestroyImmediate(obj, true);
}
}
}
}
It allows you to drag and drop one or multiple objects into the object list and then to destroy those objects.
Another way could be, as hexagonius said, instantiating the prefab into the scene and recreating a prefab from the instance by dragging it back into the project window.
Finally you can set the asset serialization mode to "force text" (Edit --> Project Settings --> Editor --> Asset Serialization). This would re-serialize your prefab as YAML. Now you can open the prefab file in a proper text editor and remove the unwanted instances. Though be careful. You may want to create a backup first if the prefab is important.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125513im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Auto-refresh assets after changing scriptable object 0 Answers
how to use Scriptable Objects outside editor 2 Answers
Referencing a ScriptableObject asset programatically 0 Answers
Scriptable Object not saving changes to a list. 0 Answers
Created Assets not persisting after closing/opening editor 1 Answer