"Recalculate" the mesh bounds to the objects rotation?

I have played around with mesh.bounds, renderer.bounds, and collider.bounds but none of them really do what i want them to do. the mesh bounds is accurate to the objects bounding box but only at rotation 0, however this is only in local space and not the world space that i want.

The renderer and collider bounds are the axis aligned bounding boxes so when an object is rotated, the “bounding-box’s bounding-box” per-se is taken. this results in bounding boxes that are deceiving when an object is rotated and doesn’t represent the apparent size of the object.

Is there any way to get, or at least imitate, a bounding box but where the box is essentially the smallest AABB box that can contain the object with its current rotation?

If you would’t care about the performance, you could iterate over all the mesh vertices contained in the GameObject, including their position into the bounds.

Bounds bounds;
MeshFilter[] meshes = GetComponentsInChildren<MeshFilter>();
    		for(int i = 0; i < meshes.Length; i++) {
    			Mesh ms = meshes*.mesh;*
  •  	int vc = ms.vertexCount;*
    
  •  	for(int j = 0; j < vc; j++) {*
    
  •  		if(i==0&&j==0){*
    
  •  			bounds = new Bounds(ms.transform.TransformPoint(vertices[j]), Vector3.zero);*
    
  •  		}else{*
    
  •  			bounds.Encapsulate(ms.transform.TransformPoint(vertices[j]);*
    
  •  		}*
    
  •  	}*
    
  •  }*
    

What I ended up doing to solve this problem for my project was to have a function that stored the target object’s rotation, then zeroed it, grabbed the meshs’s bounding box while rotation was zero, then restored the rotation.

It’s a kind of hacky solution, and I have no idea what it would do if the target was a physics object, but it worked for my needs.

Other potential work around might be adding a box collider then getting the bounds from that, then removing the box collider, though that might come with a greater performance hitch.

I ended up here not due to rotation but due to false mesh editing but in my case, simply meshFilter.sharedMesh.RecalculateBounds() fixes it

This question has been asked several times in the past and i wrote already several answers like this one.

ps: If you have several meshes in a rigid configuration (that only moves / rotates as a whole) or a single very complex mesh you might want to pre-calculate the convex hull-points of the mesh / meshes and only calculate the bounds on those vertices. This would reduce / simplify the per-frame overhead.