Editor freezes when using GetActor()->GetName() on LineTrace HitResult

Hi all, I’m having an issue in 4.7.4 with line trace debugging. I can get my linetrace fine when debugging a typical FString “You are looking at something”, but when trying to debug hit.GetActor()->GetName(), once I look at something, editor freezes. I may be missing something. I’m calling my GetTrace function from Tick. I’ve tried removing the GetTrace function and just moving the logic to Tick, same deal.

// Called every frame
void AFPSChar::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	GetTrace();
}

void AFPSChar::GetTrace()
{
	FCollisionQueryParams params;
	params.bReturnPhysicalMaterial = true;
	params.bTraceComplex = true;
	params.bTraceAsyncScene = true;
	params.AddIgnoredActor(this);
	FHitResult hit;

	if(DoTrace(params, hit))
	{
		GEngine->AddOnScreenDebugMessage(0, 1, FColor::Red, hit.GetActor()->GetName());
	}
}

bool AFPSChar::DoTrace(FCollisionQueryParams TraceParams, FHitResult HitResult)
{
	FVector CamLoc;
	FRotator CamRot;
	GetActorEyesViewPoint(CamLoc, CamRot);
	FVector Start = CamLoc;
	FVector End = CamLoc + CamRot.Vector() * TraceDistance;
	return GetWorld()->LineTraceSingle(HitResult, Start, End, ECC_PhysicsBody, TraceParams);
}

You’re not using pass by reference in your function arguments. It should be

bool AFPSChar::DoTrace(FCollisionQueryParams TraceParams, FHitResult &HitResult)

Your previous code would result in a nullptr to the AActor type in FHitResult.

Thanks. I had a brain fart and couldn’t figure out WHY I had to do what I did in my above resolution, this makes things work out the way I wanted them to.

Tested again just to be sure, your solution works perfectly. I knew I needed the ref but for some reason was getting errors so removed it. lol I was trying FHitResult& HitResult instead of FHitResult &HitResult. I’m still fairly new to pointer, references, c++ in general. Thanks again man!

No worries! By the way, there isn’t any difference between FHitResult &HitResult and FHitResult& HitResult. You may have been calling this function incorrectly.

Yea it may have been another line w/ an error, I’m just so tired today I keep forgetting how to do things that I’ve known for some time. I can’t wait to get as good at this as I was in Unity C# lol…