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
- APV gets disabled when the SubScene is closed but still loaded
- VFX Graph Particles render black when using Baked GI in URP Unlit Shader Graph
- Crash on Unity::Joint::SetJointLocalActorFrames when changing connectedBody on a ConfigurableJoint
- WebGL player crashes on RuntimeError when using the Disk LTO code optimization
- All Animators previous animations are activated while transitioning when a second split-off transition overrides the first split-off transition
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.