Check if the child of an object is active not working!!!

I have a container GameObject that has multiple children with in turn children. I need to take only the collisions of the children that are active, but when I check if achild is active, either with activeSelf or with activeInHierarchy, it always returns true, no matter if the child is active or not.
Has no sense. I don’t know what I’m doing wrong or if is a bug in Unity 2021.2.28.
Does anyone have any ideas? Thanks.

Maybe something like this:

using UnityEngine;
using System.Collections.Generic;

public class TestScript : MonoBehaviour {
    public GameObject objectToGetChildrenFrom;
    public List<GameObject> activeChildren;

    private void Update() {
        activeChildren.Clear();

        for(int i = 0; i < objectToGetChildrenFrom.transform.childCount; i++) {
            if (objectToGetChildrenFrom.transform.GetChild(i).gameObject.activeSelf) {
                activeChildren.Add(objectToGetChildrenFrom.transform.GetChild(i).gameObject);
            }
        }
    }
}

I just loop through all children of this object and if its active I add it to the list with active children. I can’t understand why it won’t work if you give more information it would be better.

Thank you for your answers!

@Cakebox I did what you suggested manually and it worked fine.
The problem is that the children are created by script from a Prefab and I inactivate them with SetActive(false), the child gameObjects are inactive and hidden but when I want to check if they are active by script they are always active.
The code is something like this.

static public bool GetCollidersBounds(GameObject go, bool searchMeshInChilds, ref Bounds bounds) {
		Component[] comps;
		List<Collider> collLst;
		Collider collTmp;
		int i;
		collLst = new List<Collider>(0);
		collTmp = go.GetComponent(typeof(Collider)) as Collider;
		if(collTmp) {
			collLst.Add(collTmp);
		}
		if(searchMeshInChilds) {
			comps = go.GetComponentsInChildren(typeof(Collider));
			if(comps != null && comps.Length > 0) {
				Debug.Log("	>> GetCollidersBounds Childs");
				for(i = 0; i < comps.Length; i++) {
					collTmp = comps *as Collider;*

_ if(comps*.transform.gameObject.activeInHierarchy) {*_

Debug.LogWarning(" >> comps_.gameObject(" + comps*.gameObject.name + “) is ACTIVE!!!”);
collLst.Add(collTmp);
}
else {
Debug.LogWarning(" >> comps.gameObject(" + comps.gameObject.name + “) is deactive”);
}*_

* }*
* }*
* }*
* if(collLst != null && collLst.Count > 0) {*
* bounds = collLst[0].bounds;*
* if(collLst.Count > 1) {*
* for(i = 1; i < collLst.Count; i++) {*
_ bounds.Encapsulate(collLst*.bounds);
}
}
return (true);
}
return (false);
}
And the script that create prefab is something like this:
public class Container{
//some variables*

* public List elements;
public void AddNewElement(GameObject prefab){
GameObject goTemp = GameObject.Instantiate(prefab);
// Do many things*

* elements.AddNewElement(goTemp);
elements[elements.Count - 1].goElement.SetActive(false);
}
}*_

I found where the problem was!
I was making a mistake. I’m sorry if you guys wasted your time.
The only thing I can do in my defense, in case someone comes across this confusion, is to explain the situation. When adding multiple children as boxes, GOBox(A).ChildBox(B).ChildBox(C).ChildElement(D) and the last box has a child element (D). What I did is that OnStart deactivated the childBox(B), therefore C and D were deactivated automatically, but when opening the GOBox(A) and activating the childBox(B) all the contained elements (C and D) were also activated . I had to do an OnStart procedure to SetActive(false) the items contained in the GOBox recursively from D to B.
Best regards.