Functions like GetActorBounds and CalculateComponentsBoundingBoxInLocalSpace sometimes return a larger bounding box than the simple collision of some static mesh.
In order to get the bounding box for only the simple collision bounds of a UStaticMeshComponent, you need to use the following code:
UStaticMeshComponent* StaticMeshComp = Get Mesh From Somewhere;
FBox Box = StaticMeshComp->GetStaticMesh()->GetBodySetup()->AggGeom.CalcAABB(FTransform());
You can then use Box.GetCenter()
or Box.GetExtent()
to get the center and extent of the bounding box.
Passing in FTransform()
as the parameter to CalcAABB
makes it return the box in the local space of the component. You can also pass in other transforms, such as the component’s own transform, to get the box in some other space.