Calculating BoxCollider bounds and center in runtime

I have a root prefab where I want to add box-collider in runtime based on bounds of child prefabs with letter meshes combined in a word. On the picture I changed size and center manually to match bounds of characters.

This is what I tried:

    Bounds bounds = new Bounds(parentObject.transform.position, Vector3.zero);
    foreach (MeshFilter meshFilter in parentObject.GetComponentsInChildren<MeshFilter>())
    {
        bounds.Encapsulate(meshFilter.mesh.bounds);
    }
    BoxCollider collider = parentObject.AddComponent<BoxCollider>();
    collider.center = bounds.center;
    collider.size   = bounds.size;

I’m getting enormous collider in this case. And it looks like somewhere wrong coordinates conversion.

How can I get size of meshes to calculate correctly offset for the next letter to add (currently I’m using hardcoded constant) ?

How can I calculate center and bounds for box collider in correct coordinate space ?

Mesh.bounds is in local space of the mesh. That means no scaling is applied and no translation. So the location of each character is completely ignored. Are the single character objects scaled or rotated in some way? If the child objects are rotated you can’t really use Mesh.bounds. If it is just scaled and translated, you have to scale and translate the bounds you get from your Mesh according to the transform of he child object,

So bounds.size need to be scaled by the childs localscale (You can use Vector3.Scale) and the center need to be offset by the localPosition of the child object.

edit
If the childs are rotated and you need an exact bounds, you may need to iterate through all vertices of each mesh, transform them into the local space of the parent (child-localspace → worldspace → parent-localspace) and use encapsulate with all vertex positions.