I have a heirarchy of game objects that have their active status animated. I’m trying to check if these objects are active, and if they are, I’m trying to reset their rotation to 0, 0, 0. I’ve been running some tests to basically print “inactive” when the object is inactive, but I can’t seem to get the script to detect the active status. I’ve tried:
if (gameObject.active == false)
if (gameObject.activeInHierarchy == false)
if (gameObject.activeSelf == false)
But none of these seem to trigger my script. Any ideas? Thanks in advance.
You didn’t specify, but if you are trying to run this on the GameObject that you have inactive, the code is never going to run because events are not run for inactive game objects.
You would have to have a separate script attached elsewhere that keeps track of them, and loops through them checking the status. If you have a parent game object with a script attached, and make all of these children, it could be as simple as:
foreach{Transform child in transform) {
if(child.gameObject.active) {
Debug.Log(child.gameObjet.name + " is active");
} else {
Debug.Log(child.gameObjet.name + " is inactive");
}
}