Bounds aren't aligned with the mesh

Guys, is there any reason for the DrawDebugBox behave like this? I’m using a basic shape in this prototype, so the pivot point is located at the center. Here is the snippet:



TArray<UStaticMeshComponent*> StaticMeshCompArr;
OrbitingActor->GetComponents(StaticMeshCompArr);
for(UStaticMeshComponent* StaticMeshComp : StaticMeshCompArr)
{
     FBoxSphereBounds BoxSphereBounds = StaticMeshComp-> GetStaticMesh()->GetBounds();
     
     DrawDebugBox(
          GetWorld(),
          StaticMeshComp->GetComponentLocation(),
          BoxSphereBounds.GetBox().GetExtent(),
          StaticMeshComp->GetComponentQuat(),
          FColor::Green,
          false,
          .03f,
          0,
          2.f
     );
}


https://preview.redd.it/umw9894c1ho61.png?width=1920

What’s wrong here?

Thanks!

PS: using GetActorLocation() and GetActorQuat() give the same result.

There’s obviously some offset you aren’t accounting for. It could be the Static Mesh offset on the actor you’re using. Try using GetWorldTransform on the Static Mesh component. You may also want to try it on an un-rotated actor and see if you just have a bad concatenation of matrices going on some where.

I’ll follow your instructions and report the results later :slight_smile:

Btw, by Static mesh offset, do you mean any translation made by SetRelativeLocation()? Because I’m using the default StaticMeshActor where the static mesh is a cube basic shape, so it has no offset.

Well, it has no offset. The image below shows that there is no difference between the actor location and the static mesh component location.



#if !(UE_BUILD_SHIPPING || UE_BUILD_SHIPPING_WITH_EDITOR) DrawDebugSphere(
  [INDENT=2]GetWorld(),
NextLocation,
5,
2,
FColor::White,
false,
3.f,
0,
2.f[/INDENT]
  );

if(TempArr[Index]->GetClass() == UStaticMeshComponent::StaticClass())
{
  [INDENT=2]UStaticMeshComponent* StaticMeshComp = Cast<UStaticMeshComponent>(TempArr[Index]);[/INDENT]
  [INDENT=2]
FBox BoundingBox = StaticMeshComp->GetStaticMesh()->GetBounds().GetBox();[/INDENT]
  [INDENT=2]
FVector ComponentLocation = StaticMeshComp->GetComponentTransform().GetLocation();[/INDENT]
  [INDENT=2]FVector BoundsCenter;
FVector BoundsExtents;
BoundingBox.GetCenterAndExtents(BoundsCenter, BoundsExtents);

FString CenterComparison = "OUTPUT: ActorCenter(";
CenterComparison += FString::Printf(TEXT("%f, "), NextLocation.X);
CenterComparison += FString::Printf(TEXT("%f, "), NextLocation.Y);
CenterComparison += FString::Printf(TEXT("%f)		"), NextLocation.Z);
CenterComparison += "ComponentCenter(";
CenterComparison += FString::Printf(TEXT("%f, "), ComponentLocation.X);
CenterComparison += FString::Printf(TEXT("%f, "), ComponentLocation.Y);
CenterComparison += FString::Printf(TEXT("%f)		"), ComponentLocation.Z);
CenterComparison += "BoundsCenter(";
CenterComparison += FString::Printf(TEXT("%f, "), BoundsCenter.X);
CenterComparison += FString::Printf(TEXT("%f, "), BoundsCenter.Y);
CenterComparison += FString::Printf(TEXT("%f)		"), BoundsCenter.Z);
CenterComparison += "BoundsExtents(";
CenterComparison += FString::Printf(TEXT("%f, "), BoundsExtents.X);
CenterComparison += FString::Printf(TEXT("%f, "), BoundsExtents.Y);
CenterComparison += FString::Printf(TEXT("%f)		"), BoundsExtents.Z);

UE_LOG(LogTemp, Warning, TEXT("%s"), *CenterComparison);

DrawDebugBox([/INDENT]
  [INDENT=3]GetWorld(),
StaticMeshComp->GetComponentTransform().GetLocation(),
BoundingBox.GetExtent(),
StaticMeshComp->GetComponentTransform().GetRotation(),
FColor::Green,
false,
.03f,
0,
2.f[/INDENT]
  [INDENT=2]);[/INDENT]
  }
 
 #endif


https://imgur.com/a/sVSoIM0

Imo, I have an ordering conflict related to execution of the instructions inside my Tick(): the DrawDebugBox related to the bounds of a static mesh (that is moving, I’m not using physics btw) is being drawn before the static mesh reachs its destination, and the DrawDebugBox call is made after the SetActorLocation call.

Yesterday, I looked for a way to guarantee that the renderer only would be able to draw the DebugBox after the actor movement. I could use a loop, but I don’t want to halt the execution until a condition returns true, or a Timer (to be triggered after a time window lesser than DeltaTime (?)).

So I have looked the FFunctionGraphTask::CreateAndDispatchWhenReady (and FSimpleDelegateGraphTask::CreateAndDispatchWhenReady too), the Async call (https://docs.unrealengine.com/en-US/…ync/index.html) and FAsyncTask, but I don’t think FAsyncTask is the best option here, since I don’t have to process a big chunk of data (to split its processing between threads )…

Is there a better solution to do this? Again, the DrawDebugBox execution happens before the SetActorLocation call, even calling it after the SetActorLocation instruction… :S