I can’t quite figure out what to do here. I’ve got a static mesh inside a UStaticMeshComponent, but its pivot is not near the actual mesh on purpose and the pivot also does not represent the rotation of the mesh. I need to get the point on the top face of my mesh as well as the rotation. If it helps, the reason I need to do this is because I want to align another actor on the surface of this mesh at the exact center. Unfortunately I can’t attach some sort of arrow or socket because this is all being generated in code.
Here is what i’ve tried so far…but none of it even comes close to working. I’m only posting this to show you i’m trying to work with getcomponentbounds and trying to create the rotation. The mesh does have collision, created on import…so maybe I can do something with that?
FVector Origin, Extent;
float SphereRadius;
UKismetSystemLibrary::GetComponentBounds(MeshComponent, Origin, Extent, SphereRadius);
FTransform OriginalTransform = this->GetActorTransform();
FVector OriginalLocation = OriginalTransform.GetLocation();
float Angle = FMath::RadiansToDegrees(acosf(FVector::DotProduct(Origin, Extent)));
FRotator RotationFromAngle = UKismetMathLibrary::RotatorFromAxisAndAngle(Origin, Angle);
APlanetAsset* Payload = GetWorld()->SpawnActor<APlanetAsset>(AssetClass, FVector::ZeroVector, FRotator::ZeroRotator);
Payload->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform, NAME_None);
Payload->SetActorRelativeLocation(Origin + Extent);
Payload->SetActorRelativeRotation(RotationFromAngle);