I am having an editor code that have inconsistent behavior. Code (CSharp): private void ClearAllDecosInternal() { GetAllWalls(); for (int i = 0; i < _wallsInLevel.Count; i++) { /* * Inconsistent behaviour -_- if (PrefabUtility.IsPartOfPrefabInstance(_wallsInLevel[i].transform.parent.gameObject)) { PrefabUtility.UnpackPrefabInstance(_wallsInLevel[i].transform.parent.gameObject, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction); } */ _wallsInLevel[i].GetComponent<WallScript>().ClearAllDecorations(); } MarkChangesToPrefab(); } Code (CSharp): public void ClearAllDecorations() { Transform[] childs = gameObject.GetComponentsInChildren<Transform>(); List<GameObject> decos = new List<GameObject>(); for (int i = 0; i < childs.Length; i++) { if (childs[i].CompareTag("WallDeco")) { decos.Add(childs[i].gameObject); } } for (int i = 0; i < decos.Count; i++) { if (decos != null) { DestroyImmediate(decos[i].gameObject); } } } It works for some of prefabs and breaks for some prefabs. The error thrown by editor is InvalidOperationException: Destroying a GameObject inside a Prefab instance is not allowed.. To answer a few questions, the walls are prefabs. The Decorations are prefab. My issue is why it works on some prefabs, and not on another. I dont want to unpack the prefab because, i want to be able to use the nested prefab feature.