UE4 C++ Line trace "Ignore Self" not working

Hello, I have a very simple line trace in my Actor Tick function:

FHitResult outHit;
FVector Start = PromptLocation->GetComponentLocation();
FVector End = DerrickCharacter->GetActorLocation();
TArray<AActor*> actorsToIgnore;

bool bHit = UKismetSystemLibrary::LineTraceSingle(GetWorld(), Start, End, UEngineTypes::ConvertToTraceType(ECC_Visibility), false, actorsToIgnore, EDrawDebugTrace::ForOneFrame, outHit, true);

And this is the function Syntax from the Unreal Docs:

static bool LineTraceSingle
(
const UObject * WorldContextObject,
const FVector Start,
const FVector End,
ETraceTypeQuery TraceChannel,
bool bTraceComplex,
const TArray< AActor * > & ActorsToIgnore,
EDrawDebugTrace::Type DrawDebugType,
FHitResult & OutHit,
bool bIgnoreSelf,
FLinearColor TraceColor,
FLinearColor TraceHitColor,
float DrawTime
)

Everything works well, except that the bIgnoreSelf argument which I set to “true” is not working. When the line trace goes through it’s own Static Mesh it detects a hit.

Keep in mind that the same exact code in Blueprint works perfectly. The line trace doesn’t detect a hit when going through the Static Mesh (when Ignore Self is ticked)
UE4_Blueprint_LineTrace

Here’s how it looks in game:

Does anyone have any idea?

you need to add the actor to the actorsToIgnore array

if it’s in the character

actorsToIgnore.Add(this);
1 Like

This solves the issue. Thanks!

But do you know why doesn’t the same code work the same in blueprints and in c++?
I’m still wondering why I have to “add (this)” to actorsToIgnore in the c++ version, and I don’t have to do that in the Blueprint version. Why the IgnoreSelf doesn’t work in c++?

I’m guessing the bp version just does that command behind the scenes in the line trace.

C++ always has more direct control of functions but there is usually some extra work with passing in structs.