Only take into account colliders' bounds on single gameobject in hierarchy

Hello again! I’ve terrible luck in getting my questions answered, since i ask for such damned difficult things, but let’s give this a shot again.

I need to find a way on how to only take into account a singular gameobject’s colliders’ bounds, in a scenario where there are children that have colliders too.

I have a script, which does some physics stuff (would take focus away from question to explain further) to an object with a rigidbody attached, based on Collider.bounds.
The issue i have, is that if i happen to have a child with colliders attached to it, it takes into account the child’s colliders too. The usual fix would be to plant a kinematic rigidbody onto this child object, but since i’m already fooling around with physics, i can’t do that, since it affects how the object behaves.

It also takes into account any triggers, for that matter, which is strange, but not actually an issue at this point.

I have a workaround, however, but it is not optimal at all, as i’d need to do this to every last collider i want manually, and not all shapes work fine with it:

public BoxCollider CollFrame; //Set in editor
void Start() {
        Bounds b;
        if (CollFrame == null)
        {
            b = collider.bounds;
        }
        else
        {
            b = CollFrame.bounds; //Must set this, otherwise it gets grumpy.
            b.center = CollFrame.center;
            b.extents = CollFrame.size / 2;
            b.max = CollFrame.center + b.extents;
            b.min = CollFrame.center - b.extents;
            b.SetMinMax(b.min, b.max); //This seems to be necessary
            b.size = CollFrame.size;
        }
      foo(b);
}

Does anyone have a nice way of getting around the usual method Collider.Bounds work, so that it can ignore its children? The problem is that my implementation specifically uses the Collider.Bounds, it doesn’t use OnTrigger or OnCollision events, so usual fixes don’t apply.

I would say the easiest way to make colliders not interact with other colliders is to use Physics settings, accessible from Edit->Project Settings->Physics (or Physics2D if you are using 2d).

From this menu, you can edit the layer collision matrix. So if you set all children in the hierarchy to be on the “Player” layer and disable Player x Player in the layer collision matrix, none of the children in the hierarchy will collide with other children with the hierarchy.

Edit:
Sorry, I totally did not understand the original question. Have you tried unparenting all the children while calculating the bounds?

void Start() {
    List<Transform> children=new List<Transform>();
    foreach(Transform child in transform) {
        children.Add(child);
    }
    foreach(Transform child in children) {
        child.transform.parent=null;
    }
    
    // code here
    
    foreach(Transform child in children) {
        child.transform.parent=transform;
    }
}