StaticMeshComponenet Transforms nullptr, Access violation?

yes I am using meta to expose the variable directly from C++ to anywhere, so now after exposing the variable I got extra parameters to set while spawning the actor

Thanks, you helped me solve a huge headache that made me lose 4 hours!

I have an ActorComponent that spawns a child ActorComponent (aka ArrowComponent). Then I was doing a Line Trace, based on the location of the child:

const FVector TraceStart = ArrowComponent->GetComponentLocation();
const FVector TraceEnd = TraceStart + (ArrowComponent->GetComponentRotation().Vector() * TileTraceDistance);

This worked in UE 4.27 and UE 5.0. But stopped working in 5.1, because ArrowComponent->GetComponentLocation() is now returning LOCAL space (so it was always 0,0,0, even although the docs say “World Space”).

So I converted it to:

const FVector LocalLocation = ArrowComponent->GetComponentLocation();
const FVector TraceStart = GetComponentTransform().TransformPosition(LocalLocation);
const FVector TraceEnd = TraceStart + (ArrowComponent->GetComponentRotation().Vector() * TileTraceDistance);

And now TraceStart correctly points to the WorldSpace location of the inner component.

1 Like