GetActorBounds affected by rotation

I’m using GetActorBounds to create a bounding sphere around my actor. I get the box extents and use it to find the box diagonal and use that as the radius for a SphereCollision.

Everything works fine, but when i rotate my actor it affects the results of GetActorBounds, changing the radius of the sphere for any rotation values different from 0, 90, 180 and 270.

My question is: how can i get the actor bounds ignoring its rotation?

Thanks!

have you solve this? i have the same question.

I didn’t solve it, but i used a workaround:

  • Set your desired Actor rotation
  • GetActorBounds with this rotation
  • Store the result inside a variable
  • Use this cached bounds value to avoid the changes in bounds with rotation.

This is not ideal though, since not all actors are perfectly square or spherical you might want to add some offsets to the cached bounds to cover the actor in all rotations.

Hope this helps!

1 Like

Be aware that the Extent of a box changes if you rotate it’s contents: it is calculated from the center to the most distanced point, but stays a box. When I applied the box extent of a component to a collisionbox size and rotated the collisionbox to the world rotation of the actor, it kept pretty good measure. This applies to sphere collisions too.

If you just need a rough sphere you can try GetSimpleCollisionRadius() AActor::GetSimpleCollisionRadius | Unreal Engine Documentation

unfortunately AActor::GetActorBounds is affected by rotation.

For getting actor bounding box and not affected by actor rotation, choose AActor::CalculateComponentsBoundingBoxInLocalSpace function

1 Like

It seems that AActor::CalculateComponentsBoundingBoxInLocalSpace is also affected by rotation (tested on UE4.26).

1 Like

It did work for me in UE4.26. It’s not affected by the actor rotation, but it’s affected by the components’ local rotation.

Then inside that function, it uses USceneComponent::CalcBounds(const FTransform& LocalToWorld) which is pretty interesting for anyone working with bounds that are not Axis Aligned.

1 Like

I know it is old, but in case someone needs the answer:

void UYourClass::GetComponentOrientedBoundingBox(USceneComponent* Component, FVector& Origin, FVector& Extent)
{
	// Calculate the right world origin
	FVector ComponentExtent;
	float ComponentRadius;
	UKismetSystemLibrary::GetComponentBounds(Component, Origin, ComponentExtent, ComponentRadius);

	// Calculate the right extent
	auto Box = Component->GetOwner()->CalculateComponentsBoundingBoxInLocalSpace(); 
	Extent = Box.GetExtent();
}