- Home /
The question is answered, right answer was accepted
Destroy a gameobject in start function
In unity3d i declared
var ribbon : GameObject;
In start function i have used code
Destroy (ribbon.gameObject, 5);
which shows 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?
Thanks in advance
Can you please be more specific? What is ribbon? How / when is it assigned? Did you attach this script to a prefab, and assign a GameObject there?
@Alec Thileniu: Didnt attach anyscript to a prefab. Its just a gameobject, a plane attached a material
What did you assign ribbon to be? Your trying to destroy the game object this script is attached to right? Try: Destroy(gameObject, 5);
@Alec Thileniu: so many gameobjects i declared. i have 2 destroy a specific one
Ok lets back up a little bit. This script is attached to a game object in the scene correct? And what are you trying to accomplish (Overall, not just with that specific line of code). I do not understand what you mean by you want to destroy a specific one. How do you chose witch one to destroy?
Answer by EtherIT · Dec 19, 2012 at 07:52 PM
Try this
Destroy(gameObject.Find("ribbon"), 3);
Answer by PushpaK · Dec 21, 2012 at 12:57 AM
I think you cant destroy any object in start function. Start functions works mostly as constructor. You have to delete object in another function such as update.
Destroy(gameObject.Find("ribbon"), 3); works in start function
Follow this Question
Related Questions
How to change a string into integer 2 Answers
Mid point of a object 1 Answer
What's my unity version? 1 Answer
Problem with getkey/getkeydown 1 Answer