- Home /
Deleting prefab located in Project in scripts
Hi, I am trying to edit a prefab located in the Project (on the hard drive) and doing some delete operations (such as Destroy a Component). But when I try to do that with DestroyImmediate, I got a "Destroying assets is not permitted to avoid data loss" error and I fail to modify the prefab.
Is there any work around with this without using DestroyImmediate()? I was thinking to create a instance of the prefab and then apply the change back to the prefab, but this does not work for cases where the GameObject is a child of the prefab.
Thanks.
Here is a sample code of what I am doing DestroyImmediate(Prefab.GetComponent()); where Prefab is the GameObject prefab.
why you are using DestroyImmediate use destroy ins$$anonymous$$d
http://docs.unity3d.com/ScriptReference/Object.DestroyImmediate.html
read the description
Have a look at here: http://forum.unity3d.com/threads/add-and-remove-components-by-scripting.33039/. A brief discussion on the same issue.
Your answer
![](https://koobas.hobune.stream/wayback/20220613200245im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Create custom warning dialog on build, if a script or gameobject exists in the scene 2 Answers
How to create gameobjects by clicking in the scene view in the editor? 1 Answer
EditorUtility.SaveFilePanel and BeginHorizontal cause "Object reference not set..." 1 Answer
exposed properties ignore prefab apply 0 Answers
Custom ordering of variables in inspector when using base and derived classes 1 Answer