How do I use GetHitResultUnderCursorByChannel in C++?

In my blueprint GetHitResultUnderCursorByChannel node I have the trace type set to “Visibility.” The function takes an ETraceTypeQuery that I’m not sure how to set in C++.

1 Like

I echo this question. It looks like GetHitResultUnderCursor has been deprecated, but the …ByChannel function’s first argument is ETraceTypeQuery. The doc for that enum just lists by the queries by number (ETraceTypeQuery | Unreal Engine Documentation).

What does ETraceTypeQuery do?

Yeah that’s kind of what I was wondering myself. There is no TTQ_Visibility, there is only TraceTypeQuery1 [2,3,4…] so how do you know which one is visibility and which ones are your custom ones that you set in the editor? Hopefully, someone can elaborate on the use of these queries.

1 Like

I’m also trying to figure out how to use this function. I’ve been trying to setup a top-down, mouse aiming character controller in c++, and I think this is the key to getting it to work.

This bugged me for ages, so I just did it in blueprints, but I stumbled across how to do it yesterday!

GetHitResultUnderCursorByChannel(UEngineTypes::ConvertToTraceType(ECC_Camera), true, Result);

That’s converting a collision channel to a trace channel; you could also convert ECC_Visibility, or any other channels you’ve defined.

16 Likes

after almost 4 years, thank you

after almost 5 years, thank you so much

after almost 6 years, thank you so many much!

after almost 7 years, thank you so many much!

after almost 8 years, thank you so very many much!

after almost 9 years, thank you so very many much!

The funny thing is, when looking at the source code of PlayerController, the ByChannel call in the end converts the TraceType back to CollisionChannel:

bool APlayerController::GetHitResultAtScreenPosition(const FVector2D ScreenPosition, const ETraceTypeQuery TraceChannel, bool bTraceComplex, FHitResult& HitResult) const
{
	return GetHitResultAtScreenPosition( ScreenPosition, UEngineTypes::ConvertToCollisionChannel( TraceChannel ), bTraceComplex, HitResult );
}

So I wonder why the original implementation has been marked deprecated and the new stuff still does the same 9 years later…

4 Likes

after almost 10 years, thank you so very many much!

this thread can’t die!

1 Like

after almost 11 years, thank you so very many much!

literally 1 year after from last post

1 Like

Huello, 12 years later, couldnt wait till december to make it exactly an year woops

Anyways, thank you so much little helper from the past :slight_smile:

1 Like