GameObject.active' is obsolete

Hi guys, I am using a simple if statement script that works very well on both iOS/Web but below shows this “warning”!
the if statement simply check to see if a certain game object is visible before it is allowed to run the remaining code…

if (Cleared.gameObject.active || Failed.gameObject.active){

WARNING: ‘UnityEngine.GameObject.active’ is obsolete. GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy

what would be the correct way to check if gameObjects are active using an if statement!?

well, what exactly are you trying to determine?

SetActive can be ignored, because that’s to set active.

testing active is ‘activeSelf’:

and ‘activeInHierarchy’:

Check what each returns, and decide for yo’self.

If you are just concerned if it’s active locally to itself, activeSelf is your choice. If you want to know if it’s active in the scene, activeInHierarchy is your choice.

2 Likes

.activeInHierarchy is basically the equivalent of the old .active.

–Eric

Yeah but;

and…

and with SetActive():

All these errors from: Assets/Standard Assets/Scripts/General Scripts/ActivateTrigger.cs

The funny thing is, this fix for the active one worked once for me, but now on this project is doesn’t.

*EDIT: uhg, I need to get more sleep, I didn’t put the true and false values inside the SetActive brackets. derp. Not sure about the other errors.

Only if you’ve modified it; the standard version that comes with Unity uses .active, which generates a warning about being obsolete but still works for now.

–Eric

I tolerate no errors in my projects, yellow or otherwise.

yeah well when I change it to setActive I get

Assets/Scripts/MAIN.js(643,44): BCE0019: ‘setActive’ is not a member of ‘UnityEngine.GameObject’. Did you mean ‘active’?

what is up with that ??

You spelled it wrong. It’s a function, not a variable.

–Eric

gameObject.SetActive(false);

oh rite its SetActive not setActive

Hi, the correct way is gameObject.SetActive(false); or gameObject.SetActive(true);

1 Like

Thank you sooo much! I had been trying to figure out why SetActive = true or false, and activeInHierarchy gives me errors when .active works and still gives me errors.