Object-oriented bounding box (from either AActor or mesh)

I’m using C++ and trying to do a sphere trace after an arbitrarily-sized projectile hits its target, in order to find the projectile’s entry point. For the sphere trace, I must know the radius of the projectile, which is dynamic and can be a rock, an arrow, etc.

I’ve read about bounding boxes, and used GetActorBounds and other ways to get the bounds of the projectile, including getting an FBox struct from the mesh’s “Bounds” attribute, but bounds seem to be axis-aligned in all cases (AABB), which means that they don’t represent the true size of the object, and change with its orientation.

Is there a way to obtain an “object-oriented” bounding box that returns the true size of the object, disregarding orientation? An [FOrientedBox][1] struct exists, but I’ve found no way to get one from the actor or mesh, so it might not be possible.

Additionally, if the above is impossible, is there a way to get, at runtime, the approximate size of a mesh, as reported in the mesh editor?

51547-approx.png

How has this not been answered yet, this was asked in 2015. Getting OBB is very important. Anyone know?

Seconded - I’d like to know this as well.

I’m still interested too if anyone know !

To get mesh size in C++ code:

auto MeshComponent = Cast<UStaticMeshComponent>(Actor->GetRootComponent());
auto StaticMesh = MeshComponent->GetStaticMesh();
auto Bounds = StaticMesh->GetBounds();

It will return FBoxSphereBounds struct which has SphereRadius and BoxExtent and of course Origin

Then you can use code like this:

FRotator Rotator = Actor->GetActorRotation();
FVector RotatedVector = Rotator.RotateVector(Bounds.BoxExtent);

But remember, the RotatedVector will be rotated BoxExtent and if you will use it in axis aligned coordinates it wont give you results that you want. E.g. if you will try to use it in DrawDebugBox. At least, it should make your life easier.

You can calculate your own Oriented Bounding Box (OBB) with a center and three extent axes using the following code:

// Get the AABB in Local space (aka Object space: such as in the Blueprint viewer). You might want to cache this result as this may be costly. 
const FBox Box = Actor->CalculateComponentsBoundingBoxInLocalSpace();
const FTransform Transform = Actor->GetTransform();

// Get World space Location.
const FVector Center = Transform.TransformPosition(Box.GetCenter());

// And World space extent
const FVector Extent = Box.GetExtent();
const FVector Forward = Transform.TransformVector(FVector::ForwardVector * Extent.X);
const FVector Right = Transform.TransformVector(FVector::RightVector * Extent.Y);
const FVector Up = Transform.TransformVector(FVector::UpVector * Extent.Z);

Source: How to calculate an Actor Oriented Bounding Box (OBB) With Unreal Engine – Flo GameDev blog