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
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
- Property List Items Overlap onto the Property List's top edge when scrolling through a long Property List
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.