I am spawing a level procedurally at runtime. For that I am using UHierarchicalInstancedStaticMeshComponents to populate it for performance reasons. I try to check if an objects already exists in the location I want to spawn in by using SweepMultiByChannel at the position with properly rotated bounding box of the mesh.
At least that is what I want to. When checking what my code does with DrawDebugBox I get boxes that are incorrectly rotated for some yaw values:
Green text means correct aligned/rotated box, red means incorrect. I am sorry for the bad lighting in the screenshot.
Following the code that I used to draw the bounding box and check for collision/other meshes:
FCollisionShape shape; FBoxSphereBounds bounds; FTransform transform; transform.SetLocation(LocationWorld); transform.SetRotation(FQuat(RotationWorld)); transform.SetScale3D(Scale); StaticMesh->BodySetup->AggGeom.CalcBoxSphereBounds(bounds, transform); FBox bbox = bounds.GetBox(); FVector boxExtend = bbox.GetExtent(); shape = FCollisionShape::MakeBox(boxExtend); FVector tracePos = bounds.Origin; DrawDebugBox(GetWorld(), tracePos, boxExtend, FQuat(RotationWorld), FColor::White, true); TArray<FHitResult> OutResults; const bool hit = GetWorld()->SweepMultiByChannel(OutResults, tracePos, tracePos, FQuat(RotationWorld), ECollisionChannel::ECC_Camera, shape);
I have isolated this code from my spawning system and placed it in BeginPlay() of a StaticMeshActor to be sure the problem is not caused by something else.
What am I doing wrong?