Visual Studio compiles out return statement

Heya,

I have a block of code that used to be working fine, but now it seems like the return statement gets compiled out. When I run it in debugger, it just skips over a return true, and goes instead to a return false.

Any idea how to keep it from skipping over the return?

bool AAsgardVRCharacter::ProjectPointToVRNavigation(const FVector& Point, FVector& OutProjectedPoint, bool bCheckIfIsOnGround)
{
	// Project the to the navigation
	UNavigationSystemV1* const NavSys = UNavigationSystemV1::GetCurrent(GetWorld());
	if (NavSys)
	{
		FNavLocation ProjectedNavLoc(Point);
		if (NavSys->ProjectPointToNavigation(Point, ProjectedNavLoc, (NavQueryExtent.IsNearlyZero() ? INVALID_NAVEXTENT : NavQueryExtent), NavData, UNavigationQueryFilter::GetQueryFilter(*NavData, this, NavFilterClass)))
		{	// If we want to check the point is on the ground
			if (bCheckIfIsOnGround)
			{
				// Trace downwards and see if we hit something
				FHitResult GroundTraceHitResult;
				const FVector GroundTraceOrigin = ProjectedNavLoc.Location;
				const FVector GroundTraceEnd = GroundTraceOrigin + FVector(0.0f, 0.0f, -200.0f);
				FCollisionQueryParams GroundTraceParams(FName(TEXT("VRCharacterGroundTrace")), false, this);
				if (GetWorld()->LineTraceSingleByProfile(GroundTraceHitResult, GroundTraceOrigin, GroundTraceEnd, UAsgardCollisionProfiles::VRRoot(), GroundTraceParams))
				{
					// If so, return the point of impact
					OutProjectedPoint = GroundTraceHitResult.ImpactPoint;
					return true; // this gets skipped
				}
				return false; // It goes straight to this
			}
			OutProjectedPoint = ProjectedNavLoc.Location;
			return true;
		}
	}
	return false;
}

Have you tried a log to see if “if (GetWorld()->LineTraceSingleByProfile …” returns true at all? Or something like this:

bool bResult = GetWorld()->LineTraceSingleByProfile(GroundTraceHitResult ...

UE_LOG(LogTemp, Warning, TEXT("Result: %d"), bResult);

Yep, it is returning true. The line immediately after, OutProjectedPoint = GroundTraceHitResult.ImpactPoint; also does get hit. However, the function still returns false. When running with the debugger it goes directy from line 20 to line 23.