unity-game-engineunityscriptgameobject

"Destroying assets is not permitted" when Destroying GameObject


I have a GameObject variable:

var ribbon : GameObject;

In the Start function, I have the code:

Destroy(ribbon.gameObject, 5); 

Which shows an error:

Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true);

How can I destroy this gameobject?


Solution

  • Try this

    Destroy(gameObject.Find("ribbon"), 5);