Skip to content

Instantly share code, notes, and snippets.

@robotron2084
Last active October 24, 2018 11:31
Show Gist options
  • Save robotron2084/8c5973d9bb24d3b2b8d2c03ddb5c79de to your computer and use it in GitHub Desktop.
Save robotron2084/8c5973d9bb24d3b2b8d2c03ddb5c79de to your computer and use it in GitHub Desktop.
REALLY breaks it! Really good.
using UnityEngine;
using UnityEditor;
public class ReallyBreakPrefabInstance
{
[MenuItem ("GameObject/REALLY Break Prefab Instance")]
public static void BreakIt()
{
Transform xForm = Selection.activeTransform;
if(xForm != null)
{
GameObject go = xForm.gameObject;
PrefabUtility.DisconnectPrefabInstance(go);
breakInstances(go);
}
}
public static void breakInstances(GameObject go)
{
SerializedObject so = new SerializedObject(go);
SerializedProperty prop = so.FindProperty("m_PrefabParentObject");
prop.objectReferenceValue = null;
so.ApplyModifiedProperties();
Component[] components = go.GetComponents<Component>();
foreach(Component c in components)
{
so = new SerializedObject(c);
prop = so.FindProperty("m_PrefabParentObject");
prop.objectReferenceValue = null;
so.ApplyModifiedProperties();
}
foreach(Transform child in go.transform)
{
breakInstances(child.gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment