Crash Issue

For some reason the code snippit below is causing a crash when looking at or walking through spawned actors.



	if (!MenuVisible)
	{
		PHelpText = "";
		FHitResult* HitRes = new FHitResult();
		FVector HitStart = FPC->GetComponentLocation();
		FVector FwdVect = FPC->GetForwardVector();
		FVector HitEnd = ((FwdVect * ReachRadius) + HitStart);
		FCollisionQueryParams* ColQueryParams = new FCollisionQueryParams();
		ColQueryParams->AddIgnoredActor(this);
		//ColQueryParams->AddIgnoredActor(TestTarget)
		if (GetWorld()->LineTraceSingleByChannel(*HitRes, HitStart, HitEnd, ECC_Visibility, *ColQueryParams))
		{
			//DrawDebugLine(GetWorld(), HitStart, HitEnd, FColor::Emerald, false, 5.5f);
			AInteractable* IntObj = Cast<AInteractable>(HitRes->Actor.Get());
			PHelpText = IntObj->IntHelpString;
		}
	}


Granted probably not the most efficient way to do this but it works for the time being, and this is in the tick function.

Check if FPC, IntObj & TestTarget are valid.
or post the crash message.

I’m pretty sure it’s because of the cast failed.



			AInteractable* IntObj = Cast<AInteractable>(HitRes->Actor.Get());
			PHelpText = IntObj->IntHelpString;


try


			AInteractable* IntObj = Cast<AInteractable>(HitRes->Actor.Get());
if(IntObj != nullptr){
			PHelpText = IntObj->IntHelpString;
}

Seems to be working now thanks. I would like this thread to remain open for the time being incase it does it again.