I want to remove a Sphere Mesh Renderer component from a certain gameobject. I want to do this in a script. How do I do it? I do not want to destroy the sphere itself, just the component


1 Answer 1


You can Destroy the component.

Be careful about which object you destroy, though. If you pass a GameObject to Destroy, you will destroy the entire thing. To destroy the component, you must pass a reference to that component specifically.

//example: destroys the MeshRenderer attached to this GameObject
var sphereMesh = GetComponent(MeshRenderer);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .