# (BUG) GetHitResultUnderCursor fails randomly

**URL:** <https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973>\
**Category:** World Creation\
**Tags:** cursor, unreal-engine, hit, Collision, question\
**Created:** [August 23, 2016, 3:30am UTC](https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973 "2016-08-23T03:30:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sveitar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sveitar/32/710746_2.png) [@Sveitar](https://forums.unrealengine.com/u/Sveitar)\
**Post date:** [August 23, 2016, 3:30am UTC](https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973/1 "2016-08-23T03:30:07Z")

</div>

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

Here is an example video showing the problem: [- YouTube](https://youtu.be/BJ85MDCJ63Y)

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);
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [August 23, 2016, 3:04pm UTC](https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973/2 "2016-08-23T15:04:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sveitar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sveitar/32/710746_2.png) [@Sveitar](https://forums.unrealengine.com/u/Sveitar)\
**Post date:** [August 23, 2016, 6:46pm UTC](https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973/3 "2016-08-23T18:46:22Z")

</div>

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:

> **[GetHitResultUnderCursor sometimes fails when clicking on landscape.](https://forums.unrealengine.com/questions/135239/gethitresultundercursor-sometimes-fails-when-click.html)**
>
> At some specific spots on a landscape I have build the GetHitResultUnderCursor methods fails even though there is landscape under the mouse. By fails I mean resulting in no hit when there obvious should have been a hit. It seems to always be the same...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [August 23, 2016, 6:58pm UTC](https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973/4 "2016-08-23T18:58:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Sveitar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sveitar/32/710746_2.png) [@Sveitar](https://forums.unrealengine.com/u/Sveitar)\
**Post date:** [August 23, 2016, 7:09pm UTC](https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973/5 "2016-08-23T19:09:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [August 23, 2016, 7:14pm UTC](https://forums.unrealengine.com/t/bug-gethitresultundercursor-fails-randomly/367973/6 "2016-08-23T19:14:22Z")

</div>

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.
