LineTraceSingleForObjects not working

I am having trouble getting the lineTraceForObjects to work in c++. When i use blueprints, it works fine, but I seem to be missing something for it to work in c++. Right now, it always returns false and doesn’t hit anything. Any ideas on how to get this to work or how to trace lines in a different way? I also had trouble getting the line visualization to work to check whats wrong.


UFUNCTION(BlueprintCallable, Category = "Phil's Nodes") void test(int x, int y, int z, FString saveDirectory, FString fileName, int FileCounter);


void UMyBlueprintFunctionLibrary11::test(int x, int y, int z, FString saveDirectory, FString fileName, int FileCounter) { std::string mySaveFile = "";
FVector TraceStart(x, y, z);
FVector TraceEnd(0.0f, 10000.0f, z);
TArray<TEnumAsByte<EObjectTypeQuery>> TraceObjects;
TraceObjects.Add(UEngineTypes::ConvertToObjectType(ECC_WorldStatic));//add your object types here.
TraceObjects.Add(UEngineTypes::ConvertToObjectType(ECC_WorldDynamic));//add your object types here.
FHitResult FirstHit(ForceInit);
TArray<AActor*> ActorsToIgnore;

UKismetSystemLibrary::LineTraceSingleForObjects(GetWorld(), TraceStart, TraceEnd, TraceObjects, false, ActorsToIgnore, EDrawDebugTrace::Persistent, FirstHit, true, FLinearColor(1, 0, 0, 1), FLinearColor(0, 1, 0, 1),20) == false);

myString += FString::SanitizeFloat(FirstHit.Location.X) + " " + FString::SanitizeFloat(FirstHit.Location.Y) + " " + FString::SanitizeFloat(FirstHit.Location.Z) + "
FString dir = "C:\\outputText\\";
FString filename = "test.txt";

FFileHelper::SaveStringToFile(myString, *(dir + filename));