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.

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.