Line Trace Crash

I’m a bit frustrated trying to figure this out, so maybe someone here can help.

I’m working on my sidescroller character. I want to shoot a trace from it 100 x in front of it.

If I just call the trace, it will return itself as the hit actor.

if I try to use AddIgnoredActor(this) or any variant that ignores itself, it crashes in the editor when the line of code runs. Any ideas as to why this is happening?

Here is the sample code:



                const FRotator Rotation = Mesh->GetComponentRotation();
		FHitResult Hit;
		FCollisionQueryParams QueryParams;
		QueryParams.bTraceComplex = false;
		QueryParams.bTraceAsyncScene = true;
		QueryParams.bReturnPhysicalMaterial = false;
		QueryParams.AddIgnoredActor(Controller->GetPawn()); //There is no crash if this line is not here.

		GetWorld()->LineTraceSingle(Hit, GetActorLocation(), FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y) * 100, ECollisionChannel::ECC_WorldStatic, QueryParams);
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, Hit.Actor->GetName());

		if (Hit.GetActor() && Hit.GetActor()->ActorHasTag("Wall"))
		{
			CharacterMovement->Velocity.Z = CharacterMovement->JumpZVelocity;
			return false;
		}

try put the trace in a custom event that fires off away from tick execution line.
I don’t know how this means in C++, but in blueprint, if your line trace hits nothing while on OnTick event execution line, it will hang the controls(except custom action buttons since they fire off tick line).

The constructor for FCollisionQueryParams takes an actor that will be ignored.


FCollisionQueryParams QueryParams(FName(TEXT("MyTrace")), true, this);

The last argument to that constructor is the actor you wish to ignore. Pass in (this) to refer to the calling class.

You could probably also just do this:


QueryParams.AddIgnoredActor(this);

Both cause a crash for me.

Did you still have AddIgnoredActor() when you tried the contructor option?

what crash are you getting?

you should post your log, around where the crash occurs.

if you are in your character class and you use

QueryParams.AddIgnoredActor(this);

you get a crash?

Does not happen for me, so post your log details please

PS, for reference, this works for me:


//Query
FCollisionQueryParams TraceParams(FName(TEXT("VictoryBPTrace::CharacterMeshSocketTrace")), true, this);
TraceParams.bTraceComplex = true;
TraceParams.bTraceAsyncScene = false;
TraceParams.bReturnPhysicalMaterial = false;
TraceParams.AddIgnoredActor(this);

I tried with the constructor, removing QueryParams.AddIgnoredActor(this) and vice-versa.

The log doesn’t seem to be providing much info, and the crash reporter itself crashes. (“The procedure entry point SetCheckUserInterruptShared could not be located in the dynamic link library. C:\WINDOWS\SYSTEM32\dbgeng.dll”)

Alright, this is a silly mistake, but I found the issue.


GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, Hit.Actor->GetName());

is where it crashes (I added some UE_LOGs to test). I’m going to guess it’s a null reference for the Hit.Actor, which would make sense. Does UE4 usually report that type of error, though?

Nope, if your code tries to use a null pointer it will simply close to desktop and you’re left in the dark where the problem is.

Always Check Your Pointers

Wiki Link: