- Home /
how to know if GameObject is active without getting warning?
I don't want to change it but see if it's active
if (GOs.gameObject.active){}
the warning I get for it
Assets/Scripts/CreateFloor.cs(263,44): warning CS0618: `UnityEngine.GameObject.active' is obsolete: `GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.'
why because of my pool and if I disable disabled object than it get's wrong and it may send an active GO to the wrong place and it could look like there's deleted GO but instead it's not
so any else way to compare if GO is active?
Answer by Chronos-L · Apr 01, 2013 at 08:12 AM
GameObject.active is obsolete now. You can use GameObject.activeInHierarchy to check if the gameObject is active in the scene.
ok thanks it works
what exactly means obsolete?
and wooooow my performance went down aloooot when I change only in to activeInHierarchy
Obsolete can be considered to be equivalent to outdated. When a function is deemed obsolete, usually it will be replaced by newer/different function(s) that can do the same thing.
For gameObject.active
, it is a getter/setter. The setter is replaced by gameObject.SetActive()
; while the getter is replaced by 2 getters: activeInHierarchy and activeSelf.
gr8 thanks now I know why performance droped I used activeself after I read this 2 articles you provided and it's parents are allways active anyway so for few 100 in few seconds that's huge difference
Answer by CiberX15 · Sep 21, 2015 at 11:27 PM
I think you can also use GameObject.activeSelf which I imagine would be faster, but it only checks that specific object and won't necessarily return false if the parent is disabled.
Reference: http://docs.unity3d.com/ScriptReference/GameObject-activeSelf.html