Search Issue Tracker
Won't Fix
Votes
0
Found in
2018.3.0a6
2018.3.0b1
Issue ID
1084109
Regression
Yes
Error: "Destroying a GameObject inside a Prefab instance is not allowed" when destroying child with Prefab from Unity 5.4
Steps:
1. Open user's attached project ("BugDestroyInsidePrefab5.2_Copy.zip")
2. Enter Play mode
3. Drag and drop Assets/Resources/PrefabTest to the Scene window
Expected: child Game object of PrefabTest gets destroyed.
Actual: child Game object of Prefab is not destroyed, an error is shown.
Reproduced with: 2018.3.0a6, 2018.3.0b3, 2019.1.0a2.
Not reproduced with: 2018.3.0a5, 2018.2.8f1 and older.
Note:
An error "InvalidOperationException: Destroying a GameObject inside a Prefab instance is not allowed" is shown when a prefab game object is trying to destroy its' child Game object. A child Game Object is not properly destroyed.
This error only appears from Prefabs generated with Unity 5.4 and older.
The bug appeared with the introduction of Nested Prefabs.
Comments (2)
-
unity_3M7vQK2p2Qly1A
Mar 27, 2021 22:04
I can do this, I solve this. Just destroy all prefab transforms. I have root _Canvas, and Prefab _Panel. And I delete like this:
foreach (Transform child in _Canvas.transform)
GameObject.Destroy(child.gameObject);
Childer objects is prefab objects. -
Peter77
Oct 02, 2018 14:30
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Sprite Importer Checkbox Label Truncated in UI (2D Template)
- Light theme icon is missing for Volume Component in the Inspector window
- Volume Profile effects are still showing and active in Game View when the Volume Profile is reset
- Shader Graph Tab Lacks Right Margin for Long Titles
- 2DLight component only renders when ShadowCaster2D components are within range in WebGL builds
Resolution Note:
There is an issue with the PrefabTest.prefab file as it is saved in a way that the user supplied scripts do not expect it to be saved.
It should not have a "Sub-Object" inside itself, as OnDestroy should have cleared it out, but for some reason it is there.
Making the prefab dirty in prefab mode will fix the issue as there is nothing from a code perspective that we can do to fix this.