- Home /
Remove empty objects from prefab
After uninstalling a plugin which left a bunch of empty components in prefabs, I am also left with these weird empty objects.
I'm assuming these nameless things inside the prefab are them. Note that only MonoBehaviour appear in the prefab without a name. All the GameObject and other classes have names.
--- !u!114 &114999955323235770
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1562992958826646}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 112998890, guid: 325c5b2a7434372429c2ca9d61dba58e, type: 3}
m_Name:
m_EditorClassIdentifier:
_guid: 9c59c1d7-de1e-484d-be2f-2eb551b3f940
And when I instantiate the prefab, they do not appear.
How do I clean these up and get rid of them? I need some automated means because the project is quite large.
I found a solution to this but won't have a chance to post the script as an answer for about a week or so. Stay tuned.
Answer by FlaSh-G · Apr 04, 2018 at 12:36 PM
I guess a combination of
AssetDatabase.LoadAllAssetsAtPath
(https://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAllAssetsAtPath.html),Object.DestroyImmediate
(https://docs.unity3d.com/ScriptReference/Object.DestroyImmediate.html) for objects without a name andAssetDatabase.SaveAsset
(https://docs.unity3d.com/ScriptReference/AssetDatabase.SaveAssets.html)
should do the trick.