Crash from OutResult.IsNormalized() help?

This crash started happening after reworking the WeaponTrace() function in the shootergame example to support a box trace.

MachineId:91B8202E498AAFACFF96608F5CE9926C
EpicAccountId:7db26073e7204773b0303ae07338c809

Unknown exception - code 00000001 (first/second chance not available)

Assertion failed: OutResult.Normal.IsNormalized() [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.5\Engine\Source\Runtime\Engine\Private\Collision\CollisionConversions.cpp] [Line: 36] 

KERNELBASE + 115496 bytes
UE4Editor_Core + 3174852 bytes
UE4Editor_Core + 1677512 bytes
UE4Editor_Core + 1566866 bytes
UE4Editor_Engine + 11536813 bytes
UE4Editor_Engine + 11548421 bytes
UE4Editor_Engine + 11508157 bytes
UE4Editor_Engine + 11621051 bytes
UE4Editor_Engine + 11617635 bytes
UE4Editor_Engine + 11755771 bytes
UE4Editor_ShooterGame + 1280582 bytes
UE4Editor_ShooterGame + 761198 bytes
UE4Editor_ShooterGame + 874121 bytes
UE4Editor_ShooterGame + 1004317 bytes
UE4Editor_ShooterGame + 1075571 bytes
UE4Editor_Engine + 15815490 bytes
UE4Editor_Engine + 6411406 bytes
UE4Editor_Engine + 6464208 bytes
UE4Editor_Engine + 6402091 bytes
UE4Editor_Engine + 6462880 bytes
UE4Editor_ShooterGame + 1234389 bytes
UE4Editor_Engine + 1652387 bytes
UE4Editor_Engine + 8779958 bytes
UE4Editor_Engine + 8829659 bytes
UE4Editor_Core + 746772 bytes
UE4Editor_Core + 747165 bytes
UE4Editor_Core + 870341 bytes
UE4Editor_Engine + 9060549 bytes
UE4Editor_Engine + 8971673 bytes
UE4Editor_Engine + 8982533 bytes
UE4Editor_Engine + 5590422 bytes
UE4Editor_Engine + 5619151 bytes
UE4Editor_UnrealEd + 1895346 bytes
UE4Editor_UnrealEd + 6486374 bytes
UE4Editor!FEngineLoop::Tick() + 3524 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\launchengineloop.cpp:2129]
UE4Editor!GuardedMain() + 479 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\launch.cpp:133]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\windows\launchwindows.cpp:125]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\windows\launchwindows.cpp:201]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

And here is my altered WeaponTrace()

FHitResult AShooterWeapon::WeaponTrace(const FVector& StartTrace, const FVector& EndTrace) const
{
	/*
	static FName WeaponFireTag = FName(TEXT("WeaponTrace"));

	// Perform trace to retrieve hit info
	FCollisionQueryParams TraceParams(WeaponFireTag, true, Instigator);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = true;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingle(Hit, StartTrace, EndTrace, COLLISION_WEAPON, TraceParams);

	return Hit;
	*/

	static FName WeaponFireTag = FName(TEXT("WeaponTrace"));

	// Perform trace to retrieve hit info
	FCollisionQueryParams TraceParams(WeaponFireTag, true, Instigator);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = true;
	//TraceParams.TraceTag = WeaponFireTag;

	FHitResult Hit(ForceInit);
	GetWorld()->LineTraceSingle(Hit, StartTrace, EndTrace, COLLISION_WEAPON, TraceParams);

	FVector NewEnd;

	AActor* ActorThatWasHit;

	bool bHitShooterCharacter = false;

	ActorThatWasHit = Hit.GetActor();

//	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("TraceExtemt:"));
	//GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TraceExtent.ToString());

	if (Hit.GetActor())
	{
		// if the hit actor was a player, we dont need to do anything else.
		if (Cast<AShooterCharacter>(Hit.GetActor()))
		{
			return Hit;

		}

		//otherwise we need to do a box trace that only searches for players.
		else
		{
			TArray<FHitResult> ListOfHits;
			FCollisionShape shape = FCollisionShape::MakeBox(TraceExtent);
			FCollisionResponseParams ResponseParam(ECollisionResponse::ECR_Ignore);
			ResponseParam.CollisionResponse.Pawn = 1;
			GetWorld()->SweepMulti(ListOfHits, StartTrace, EndTrace, FQuat(), COLLISION_WEAPON, shape, TraceParams, ResponseParam);

			//if we hit something  we do some stuff to get where the new line trace should trace to.
			if (ListOfHits.Num() > 0)
			{
				int32 numbertoprint;
				numbertoprint = ListOfHits.Num();
				//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::FromInt(numbertoprint));

				for (int32 i = 0; i < ListOfHits.Num(); i++)
				{
					//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::FromInt(i + 1));
					if (ListOfHits[i].GetActor())
					{
						if (Cast<AShooterCharacter>(ListOfHits[i].GetActor()))
						{
							//GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("I HIT A SHOOTERCHARACTER"));

							//FHitResult NewHitResult(ForceInit);
							//GetWorld()->LineTraceSingle(NewHitResult, StartTrace, ListOfHits[i].ImpactPoint, COLLISION_WEAPON, TraceParams);

							//return NewHitResult;

							NewEnd = ListOfHits[i].ImpactPoint;

							FVector Test;

							const int32 RandomSeed = FMath::Rand();
							FRandomStream WeaponRandomStream(RandomSeed);

							Test = ListOfHits[i].ImpactPoint - StartTrace;

							FVector Cone = WeaponRandomStream.VRandCone(Test, 0, 0);

							NewEnd = StartTrace + Cone * 10000;

							ActorThatWasHit = ListOfHits[i].GetActor();
							bHitShooterCharacter = true;

							//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, NewEnd.ToString());

							break;

							//return ListOfHits[i];
						}

					}

				}
			}
		}
	}
	// we didnt hit anything so we do the same as above
	else
	{
		//GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Cyan, TEXT("Hit a BSP"));

		TArray<FHitResult> ListOfHits;
		FCollisionShape shape = FCollisionShape::MakeBox(TraceExtent);
		FCollisionResponseParams ResponseParam(ECollisionResponse::ECR_Ignore);
		ResponseParam.CollisionResponse.Pawn = 1;
		GetWorld()->SweepMulti(ListOfHits, StartTrace, EndTrace, FQuat(), COLLISION_WEAPON, shape, TraceParams, ResponseParam);

		if (ListOfHits.Num() > 0)
		{
			int32 numbertoprint;
			numbertoprint = ListOfHits.Num();
			//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::FromInt(numbertoprint));

			for (int32 i = 0; i < ListOfHits.Num(); i++)
			{
				//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::FromInt(i + 1));
				if (ListOfHits[i].GetActor())
				{
					if (Cast<AShooterCharacter>(ListOfHits[i].GetActor()))
					{
					//	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("I HIT A SHOOTERCHARACTER"));

						//FHitResult NewHitResult(ForceInit);
						//GetWorld()->LineTraceSingle(NewHitResult, StartTrace, ListOfHits[i].ImpactPoint, COLLISION_WEAPON, TraceParams);

						//return NewHitResult;

						NewEnd = ListOfHits[i].ImpactPoint;

						FVector Test;

						const int32 RandomSeed = FMath::Rand();
						FRandomStream WeaponRandomStream(RandomSeed);

						Test = ListOfHits[i].ImpactPoint - StartTrace;

						FVector Cone = WeaponRandomStream.VRandCone(Test, 0, 0);

						NewEnd = StartTrace + Cone * 10000;

						ActorThatWasHit = ListOfHits[i].GetActor();
						bHitShooterCharacter = true;

					//	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, NewEnd.ToString());

						break;

						//return ListOfHits[i];
					}

				}

			}
		}
	}

	if (bDrawWeaponTrace)
	{
		GetWorld()->DebugDrawTraceTag = WeaponFireTag;
	}
	else
	{
		GetWorld()->DebugDrawTraceTag = FName(TEXT(""));
	}

	// do a normal line trace for where we hit the player to ensure that it wasnt through geometry.
	if (ActorThatWasHit && bHitShooterCharacter)
	{
		FHitResult FinalHitResult(ForceInit);
	//	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, NewEnd.ToString());
		GetWorld()->LineTraceSingle(FinalHitResult, StartTrace, NewEnd, COLLISION_WEAPON, TraceParams);

		return FinalHitResult;
	}

	FString stringtoprint;

	Hit.BoneName.ToString(stringtoprint);
//	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, stringtoprint);

	//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Charge amount, server: %f"), CurrentChargeAmount));

	return Hit;
}

And honestly if there is a better way to handle this (either making the trace bigger without all the extra tracing, or just having “bullet magnetism” on the trace) that I could do instead of this feel free to let me know.

It seems you’re accessing an undefined HitResult, depending on your StartTrace/EndTrace you could have no hit in the world.

GetWorld()->LineTraceSingle(Hit,…) will return true if it has hit something, false otherwise. You should start by always doing your trace within a if condition to be sure you won’t access and use uninitialized HitResult.

FHitResult Hit
if( GetWorld()->LineTraceSingle(Hit,...) )
{
    //use "Hit"
}

I hope it helps