Getting height value of x,y coordinate of Landscape

FVector UBPFunctionLibrary::BPGetGroundPoint(UObject* WorldContextObject, FVector VectorNeedToAdjust)
{
if (!WorldContextObject)
return VectorNeedToAdjust;
UWorld* World = WorldContextObject->GetWorld();
if (!World)
return VectorNeedToAdjust;
AActor* LandActor = UGameplayStatics::GetActorOfClass(WorldContextObject, ALandscape::StaticClass());
ALandscape* Land = Cast(LandActor);
if (Land)
{
TOptional Height = Land->GetHeightAtLocation(VectorNeedToAdjust);
if (Height.IsSet())
{
return FVector(VectorNeedToAdjust.X, VectorNeedToAdjust.Y, Height.GetValue());
}
else
{
UE_LOG(LogTemp, Warning, TEXT(“Height value is not set for location: %s”), *VectorNeedToAdjust.ToString());
}
}
return VectorNeedToAdjust;
}

/*
Here’s my code. It takes an input vector with an incorrect height and outputs a coordinate that aligns perfectly with the ground. I think it works really well and is more elegant than using ray tracing! If you want to use this code, make sure to include the Landscape module. Hope it helps!
*/