x


How to make an gameObject invisible and disappeared

I have 2 questions:

  1. How to make an gameObject invisible but I can still interact with it.
  2. How to make an gameObject disappeared and reappeared without destroying and creating a new object.
more ▼

asked Nov 14 '09 at 07:22 PM

nntvog gravatar image

nntvog
84 1 2 6

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

6 answers: sort voted first

You can turn off the rendering of a GameObject by disabling its MeshRenderer component, e.g.

GetComponent(MeshRenderer).enabled = false;

You can disable a GameObject entirely by making it inactive, e.g.

gameObject.active = false;
more ▼

answered Nov 14 '09 at 08:41 PM

technicat gravatar image

technicat
1.5k 10 11 34

where does this text go and what do i attach it to? i just get error if i put it into the update and attach it to an object.

Oct 14 '11 at 05:03 PM tensus2000

you cannot use adjust a property on an uninstantiated object (e.g. a function call)

GetComponent("RPGCamera").enabled = true;

I would go into your RPGCamera script and generate some setters and getters.

then you could say: if (Input.GetKeyUp (KeyCode.F)){ MainCamera.setEnabled = false; RPGCamera.setEnabled = true; }

Nov 14 '12 at 01:13 AM Cyber_Defect

@tensus2000 It is important that you use Unity 3. If you use Unity 4 you should use this script http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActive.html

Jan 05 at 06:59 PM Lost_C4

ok, apparently you can... odd.

Mar 22 at 12:38 AM Cyber_Defect

Hi technicat! Two small additions to these good answers

  1. "gameObject.active = false" does not stop the object from rendering.
  2. "gameObject.renderer.enabled = false" only works if you have one renderer on your object, at the top level. If you have a complex model with lots of parts and a hierarchy then one must hunt them all down and disable them all.
Apr 23 at 02:22 AM psantoki
(comments are locked)
10|3000 characters needed characters left
renderer.enabled = false;

is a shortcut you can use to do the same thing as the first example.

more ▼

answered Nov 16 '09 at 11:22 PM

Jessy gravatar image

Jessy
15.6k 72 95 196

I just realized today I forgot about the shortcut in my answer! The shortcut also has the advantage of working with non-mesh renderers (I assume), like LineRenderer. Still, for those getting used to the Unity model, it's useful to make obvious the conceptual connection between the line of code and manually clicking that particular component checkbox in the Inspector.

Nov 17 '09 at 02:45 AM technicat
(comments are locked)
10|3000 characters needed characters left

Just to answer your question regarding physics..

renderer.enabled is different to renderer.gameObject.active in that .enabled will continue to consider physics on your invisible object.

more ▼

answered Oct 20 '10 at 11:39 AM

Mann1ng gravatar image

Mann1ng
142 3 4 6

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

i have a question, if i set gameObject.active = false; does it stop the engine from making calculations (like physics ones) ?

I am preallocating 10 objects and placing them out of screen, but i don't want them to generate any collision/calculation,etc when i have them in this "not used" state.

Would gameObject.active = false; achieve this?

Thanks

more ▼

answered Nov 19 '09 at 11:32 AM

pablo gravatar image

pablo
14 6 6 8

@pablo I think you should copy this question into a new question as you should only reply to the first question if you have the answer or a comment. Hope you will understand.

Oct 14 '11 at 05:29 PM BerggreenDK
(comments are locked)
10|3000 characters needed characters left

maybe set renderer.material.color.a = 0 to set alpha to 0, then you could even put the camera behind or inside the character and view from inside that mesh at like .25 opacity, depending on how cartoony youre going this could like kinda sweet

more ▼

answered Jul 30 '12 at 09:11 PM

insanetheta gravatar image

insanetheta
1 1 1 1

(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:

x5070
x2083
x64

asked: Nov 14 '09 at 07:22 PM

Seen: 26786 times

Last Updated: Apr 23 at 02:22 AM