x


Problem with Destroy()

Okay, so I am making a custom editor game. There is a variable called "selectedObject", that stands for the object that is currently selected and ready to be edited.

if (GUI.Button(Rect(135,215,100,20),"Delete")) {
Destroy(selectedObject);
}

And whenever I click the "Delete" button in game mode, to delete the selected object, I get this error... :(

Can't remove component.
Can't remove Transform because MeshFilter, BoxCollider, MeshRenderer depends on it

Any ideas?

more ▼

asked Aug 18 '12 at 08:01 PM

THEpancakes gravatar image

THEpancakes
88 7 13 17

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Destroy(selectedObject.gameObject);

destroy GameObject, if you want to destroy whole object. Transform is just a component that can't be destroyed without GameObject

more ▼

answered Aug 18 '12 at 08:02 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

Thanks, that worked! :)

Aug 18 '12 at 08:07 PM THEpancakes
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3694
x764

asked: Aug 18 '12 at 08:01 PM

Seen: 161 times

Last Updated: Aug 18 '12 at 08:07 PM