- Home /
Destroying a gameobject using the transform component
I came across an error caused by me cloning a bunch of objects and deleting them with Destroy(transformvariable) Apparently it wont destroy the object, so I tried to use the .gameObject variable, didn't work (told me that it wasn't existent in objects). Any way around this?
Please show the relevant code and exact error; using the .gameObject bit is usually correct so there's something else to this
As @getyour411 mentions, seeing the code you are having trouble with will produce a focused answer. From any transform, you can get the gameObject:
Destory(theTransform.gameObject);
Can you post what you did to clear up the issue you were having just so that future users of UA that come across the same problem can see the solution.
Answer by giano574 · Mar 07, 2014 at 07:41 AM
You can't destroy a Transform (component of GameObject), only the GameObject itself. Therefore getting the GameObject that the Transform component is attached to will make it possible to destroy it.
Destroy(transform.gameObject);
Note: I am aware that the answer was already posted as a comment, but an answer is easier to see in the future.