(BUG) GetHitResultUnderCursor fails randomly

This function is not working properly, some times (comepletely random) the function fails (returns false).

Here is an example video showing the problem: - YouTube

And here is the relevant code:

void ACFPlayerController::WorkerMoveTo()
{
	FHitResult HitResult;
	if (GetHitResultUnderCursor(ECollisionChannel::ECC_WorldStatic, false, HitResult))
	{
		FVector TargetLocation = HitResult.Location;
		TargetLocation.Z += 10.0f;
		FActorSpawnParameters SpawnParameters;
		SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
		GetWorld()->SpawnActor<AActor>(MoveToIndicatorClass, TargetLocation, FRotator(0.0f, 0.0f, 0.0f), SpawnParameters);
		ServerWorkerMoveTo(TargetLocation);
	}
	else
	{
			GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::, TEXT("GetLocationUnderPlayerCursor Failed!"));
	}
}

void ACFPlayerController::ServerWorkerMoveTo_Implementation(FVector TargetLocation)
{
	if (WorkerUnit)
	{
		AAIController* const Controller = Cast<AAIController>(WorkerUnit->GetController());
		if (Controller)
		{
			Controller->MoveToLocation(TargetLocation);
		}
	}
}

Hello User-1548785606,

When looking into the function’s functionality, I noticed that it has a deprecated message on it. “Use new GetHitResultUnderCursorByChannel or GetHitResultUnderCursorForObject” Can you try using the GetHitResultUnderCursorByChannel function to see if it may work correctly for you? It’s possible that this has already been fixed with that new function. If it isn’t, please let me know and I’ll investigate.

Hi Matthew, thanks for your answer. I was previously using GetHitResultUnderCursorForObject. I tried with GetHitResultUnderCursorByChannel and finally with GetHitResultUnderCursor. It’s the same thing. I’ve readed the source for those functions and basically all do the same thing and what seems to fail is the line trace through the landscape. If I click over a mesh it works flawlessly.

Then I found this:

It seems that if this is the case, there may still be a workaround for it. From what I’m reading, this is specific to Landscapes. Can you trying to add collision volumes that mimic the floor in dimension and size and then use that for your traces instead of the landscape itself?

Yes, that is exactly what I did since my landscape is flat and it’s pretty easy. But for sculpted landscapes this would be a pain.

I understand, but it’s currently the only kind of workaround I can think of. Unfortunately as stated in those other threads, we’re waiting on Nvidia’s response to this issue and can’t do much about it in the meantime.