I always get back a local XYZ for my component when using GetComponentLocation() and when using a GetComponentTransform().GetLocation(). I have seen both say they return world coordinates. If I am incorrect about that, how do I get world coordinates of a component? This particular component is a StaticMeshComponent. If I am correct, will this be fixed or is my confusion the result of old documentation?
When I display the Vector of the result of my GetComponentLocation(), they are the values relative to the Blueprint root. The same applies to the GetComponentTransform().GetLocation().
(Ensure to #include “Engine.h” so we can use GEngine functions)
ATestActor::ATestActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
StaticMeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
}
void ATestActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
ComponentLocation = StaticMeshComp->GetComponentLocation();
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, FString::Printf(TEXT("Location: %f, %f, %f"), ComponentLocation.X, ComponentLocation.Y, ComponentLocation.Z));
}
With this code, I was able to create a blueprint based on my actor class, place it in the level, and see the correct location being printed out on Tick
Give this a try and let me know if you have any further questions.
I tried this and you were correct. It was my debugging that was flawed. I am getting back world coordinates on the component, but the component is not following the main mesh, causing the coordinates I was getting back, to seem as if they were local since they were very close to 0,0,0. The component isn’t attached to the mesh for some reason. I would guess it’s timing due to creating the subcomponent in C++, before the blueprint was finished loading. I will try a deferred spawn and hack the timing for creation. If it doesn’t work, I’ll open a question about that separately. Thanks for taking the time to verify (unfortunately) my flawed debugging.