- Home /
Problems with Game object visible when active is false
Hi,
I'm a newbie to unity so this might be a basic problem but I can't find a solution.
I've a public game object var with the script "name.active = false".
When I attach a simple mesh to this var, it works perfectly (I want it to be invisible and inactive). But when it's a mesh within a game object it's inactibe but still visible.
If someone can help.
Thanks
Could you clarify a bit why you're making the name inactive, and not the GameObject?
Also, I'm not sure what you mean by attaching a mesh to the "var". A mesh is attached to a $$anonymous$$eshFilter component of a GameObject, and if that GameObject's "active" property is set to "false", it'll be made invisible. Perhaps you have a mesh attached to a child object in its hierarchy?
About the name, it's the name of the public var. Like this I declare public GameObject $$anonymous$$emory1; and later $$anonymous$$emory1.active = false;
I indeed had a problem in my hierarchy. Thank you !!!
And by the way I guess it is not possible so to make inactive and invisible a child object by deactivating the parent?
for that you can use:
GameObject.SetActiveRecursively
edit:
as in gameObject.SetActiveRecursively(false); // to turn off
SetActiveRecursive() can be expensive, so avoid doing it every frame, or at least, avoid doing it every frame to lots of objects, especially if you're targeting mobile.
If you need to do this sort of thing and the hierarchy of the Transform you're enabling/disabling is fixed, you're better to create a script that discovers and caches the hierarchy, so that you can iterate over each GameObject in that hierarchy and set it it directly, ins$$anonymous$$d of finding each item every time.
I suspect SetActiveRecursively() is doing a lot of GetComponent() and then looping over children etc... etc...
Answer by andy-go · Jul 24, 2012 at 12:57 PM
Ok I don't think i'll be using it too much so it should be ok. Thanks.
Answer by andy-go · Jul 24, 2012 at 12:57 PM
OK I don't know exactly how it is going to work so I'll try this way to begin with (it looks easier to begin). And if I meet problem, I'll try your method. Thanks