- Home /
Cannot Destroy Instanitaed prefab.
Gents,
This is mind boggling to me, for whatever reason ( maybe a bug) I cannot destroy an instantiated object after being transferred from one GameObject Variable to Another.
void OnCreateHolder()
{
if (Holder != null)
{
if (Holder2 != null)
{
Destroy(Holder2.gameObject);
}
Holder2 = Holder.gameObject;
}
Holder is an instantiated Object that if I try and destroy does not give me the error message. However I am assigning Holder to Holder2 without or without using the .gameobject tag it gives me the following error:
Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); UnityEngine.Object:Destroy(Object)
Please help, thank you.
Also please note that it does actually delete it, even though the error pops up. However in IOS, it just stops working..
Hi,
The script is around 500 lines long.. however i finally found the problem, i had assigned a gameobject to holder first time round, therefore it was transferring it and then trying to destroy the prefab.
Thanks anyway.
Not the whole script but when you talk about some strange variables where we have no idea what type they have we can't say much about that.
Next thing is that you don't try to destroy the instantiated object. You try to destroy the asset, the source object. That's why it would help to see where and how the reference in Holder and Holder2 are set. The variable name doesn't give any hint what's in it.
Program$$anonymous$$g is a kind of communication, mainly with a PC / compiler. The compiler can interpret what you've written but it can never understand what it does. The compiler don't care about variable names, but humans do.
I'm getting tired of those "maybe a bug" annotations. The most common source of errors is **B$$anonymous$$AC ;)
Answer by DaveA · Jan 15, 2013 at 10:36 PM
If you really want to remove an asset use DestroyImmediate (theObject, true);
Destroy does not let go the object until after the frame