How: UnPreFab a PreFab? (Not just break it...)

There are times when I have a prefab, and I want to make changes to one and have it NOT be a prefab any more. If I make changes, it becomes a BROKEN PREFAB, but not a clean set of objects. It continues to be a prefab - albeit broken.

I just want to select a GameObject or family of GameObjects and say “Prang! You are now mortal. You are free of your bonds of immortality and are a prefab no longer.”

Is there a way to just “Clear Prefab”?

Editor Scripting?

I would imagine something like “SetPrefabType” to “PrefabType.None” but I can only find “GetPrefabType”.

GetPrefabType
http://unity3d.com/support/documentation/ScriptReference/EditorUtility.GetPrefabType.html

PrefabType

any news ? feature would be great !

Can’t be done. I have investigated this already for so long, and it is a no go, for some obscure reason :slight_smile:
The only way to make an object a non prefab, is by disconnecting it (either by hand, or by code), and then delete the prefab master from the project assetdatabase. Then it will look normal again.

There’s now a way to do this:

Select the object in the Hierarchy > Menu > GameOject > Break Prefab Instance

Here is a code:

static public class PrefabReset
{
    [MenuItem("GameObject/Remove Prefab Link")]
    static private void ResetPrefabSelected()
    {
        ResetPrefabParent(Selection.objects);
    }

    static public void ResetPrefabParent(params Object[] objs)
    {
        foreach (var obj in EditorUtility.CollectDeepHierarchy(objs))
        {
            if (AssetDatabase.Contains(obj))
                continue;

            ResetPrefabLink(obj);
        }
    }

    static private void ResetPrefabLink(Object obj)
    {
        if (obj == null)
            return;

        var destSO = new SerializedObject(obj);

        destSO.FindProperty("m_PrefabParentObject").objectReferenceValue = null;
        destSO.FindProperty("m_PrefabInternal").objectReferenceValue = null;
        destSO.ApplyModifiedProperties();
    }
}
1 Like

Sadly, the GameObject > Break Prefab Instance does not “unprefab a prefab”, but simply makes it a broken prefab.

But the code above will do so.

And, yes, Thanks for the code!

I’ve not tried it, but it looks correct.

Also, we’ve put in a ticket to review the “Break Prefab” item, to make sure this is the expected behaviour.

I had the same problem. I fixed it by right clicking the object you want to un-prefab in the Hierarchy, then select unpack prefab completely. This will make the object no longer a prefab, and you can then just delete the prefab. I’ve put a link to a short clip of myself doing so if you want to check it out.

hope this helps!

lol I just realized this thread was created 6 years ago

3 Likes

No no! Thank you. People still need this info, so don’t apologize for putting it out, I literally just searched for this!

2 Likes

I think it is great you put in a solution, even if the solution is something that didn’t exist back when this thread was active (Which it didn’t)