- Home /
How to make a gameObject invisible in unity
I am attempting to make a Unity gameObject invisible through code. So far I have tried (On a script attached to the gameObject I want to make invisible): this.renderer.enabled = false
this.enabled = false
this.gameObject.enabled = false
this.gameObject.renderer.enabled = false
And on my player script: other.gameObject.enabled = false
other.gameObject.renderer.enabled = false
I have also tried Destroy (other.gameObject)
but it doesn't achieve what I want from it.
Thanks for your help
Answer by Mr. Mud · Feb 01, 2015 at 10:02 PM
It seems like you tried a lot of ways to turn the object invisible. But where exactly did you place these statements? Some functions get called automatically by Unity, while others won't. Also, when you state that it does not achieve the effect you want, do you mean that the object does not become invisible? Or is it the way it becomes invisible (in an instant) that you don't like? The latter requires some more work.
Here is an example of an script that will disable a GameObject in its entirety; it won't be rendered, physics won't affect it and Updated functions on its components won't be executed. Do note however that this might or might not work depending on the version of Unity you are running.
using UnityEngine;
public class Example : MonoBehaviour
{
public void Awake()
{
this.gameObject.SetActive(false);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613182123im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Renderer.enable for GameObject[]? 3 Answers
animation.speed does not work when disabling/enabling renderer 1 Answer
Gameobject with many child objects disable mesh not working. 0 Answers
Keypress.ismine? 0 Answers
Cannot select Animation Event 3 Answers