I am trying to log the name of an actor when it is hit with a raycast. I just can’t seem to get it to work. The engine crashes when the following code is executed.
FHitResult* Hit = new FHitResult();
float RayLength = 5000;
FVector StartLocation = CameraComponent->GetComponentLocation();
FVector EndLocation = StartLocation + (CameraComponent->GetForwardVector() * RayLength);
FCollisionQueryParams CollisionParameters;
ActorLineTraceSingle(*Hit, StartLocation, EndLocation, ECollisionChannel::ECC_WorldDynamic, CollisionParameters);
if (Hit != NULL) {
UE_LOG(MyLog, Log, TEXT("You hit: %s"), *Hit->GetActor()->GetName()); // This line causes the crash
}
Any help would be greatly appreciated!