Assertions fail in Development Editor but succeed in Debug Editor

Hello All,

I’ve got a problem with some assertions using the “check” macro. For some reason the assertion fails when I run my game in Development Editor mode but succeeds when I run it in Debug Editor mode. Below I have added the code which produces the error.


FVector UTile::GetEdgeInDirection(FVector Direction){
    check(Direction.Size() > 0.1f && "[UTile::GetEdgeInDirection] Direction is to small");

    // get the direction in radians (from the center of the tile)
    float RadianDirection = UKismetMathLibrary::Atan2(Direction.Y, Direction.X);
    float xFactor = UKismetMathLibrary::Cos(RadianDirection);
    float yFactor = UKismetMathLibrary::Sin(RadianDirection);

    FVector EdgeDirection = (Rotation * FVector::ForwardVector * xFactor + Rotation * FVector::RightVector * yFactor);
    FVector EdgeDirectionNormalized = EdgeDirection.GetSafeNormal();
    FVector EdgePosition = GetWorldPosition() + EdgeDirectionNormalized * UWorldSevenUtilities::GetTileSize() / 2.0f * GetScale();

    check(EdgeDirection.Size() > 0.1f && "[UTile::GetEdgeInDirection] Direction is small");
    check(EdgeDirectionNormalized.Size() > 0.1f && "[UTile::GetEdgeInDirection] EdgeDirectionNormalized is small");

    if (Direction.X > 50) {
        DrawDebugSphere(GetWorld(), EdgePosition, 5.0f, 6, FColor::Black, false, 5.0f);
        DrawDebugDirectionalArrow(GetWorld(), GetWorldPosition() + FVector::UpVector * 2.0f, GetWorldPosition() + FVector::UpVector * 2.0f + EdgeDirectionNormalized * UWorldSevenUtilities::GetTileSize() / 2.0f * GetScale(), 5.0f, FColor::White, false, 5.0f);
    }

    return EdgePosition;
}

The check which fails is the check which makes sure that EdgeDirectionNormalized is not close to zero. All other check succeed. For some reason EdgeDirectionNormalized is close to zero in Development Editor mode but is fine in Debug Editor mode. I have tried using other normalization functions such as Normalize and GetUnsafeNormal but they all have the same issue. And it can’t be that the vector that I normalize is close to zero and therefore GetSafeNormal returns the zero vector because I check that right above the check which fails and that one succeeds.

Any ideas why this might be happening?

It gets weirder…

this code works both on Debug Editor mode as well as Development Editor mode.


FVector UTile::GetEdgeInDirection(FVector Direction){
    check(Direction.Size() > 0.1f && "[UTile::GetEdgeInDirection] Direction is to small");

    // get the direction in radians (from the center of the tile)
    float RadianDirection = UKismetMathLibrary::Atan2(Direction.Y, Direction.X);
    float xFactor = UKismetMathLibrary::Cos(RadianDirection);
    float yFactor = UKismetMathLibrary::Sin(RadianDirection);

    FVector EdgeDirection = (Rotation * FVector::ForwardVector * xFactor + Rotation * FVector::RightVector * yFactor);
    FVector EdgeDirectionNormalized = EdgeDirection.GetSafeNormal();
    FVector EdgePosition = GetWorldPosition() + EdgeDirectionNormalized * UWorldSevenUtilities::GetTileSize() / 2.0f * GetScale();

    check(EdgeDirection.Size() > 0.1f && "[UTile::GetEdgeInDirection] Direction is small");
    check(EdgeDirectionNormalized.Size() > 0.1f && "[UTile::GetEdgeInDirection] EdgeDirectionNormalized is small");

    DebugUtilities::PrintToScreen(FString::Printf(TEXT("We got a edgedir size of %s"), *EdgeDirection.ToString()), 10.0f);
    DebugUtilities::PrintToScreen(FString::Printf(TEXT("We got a normalized size of %s"), *EdgeDirectionNormalized.ToString()), 10.0f);

    if (Direction.Y > 50) {
        DrawDebugSphere(GetWorld(), EdgePosition, 5.0f, 6, FColor::Black, false, 5.0f);
        DrawDebugDirectionalArrow(GetWorld(), GetWorldPosition() + FVector::UpVector * 2.0f, GetWorldPosition() + FVector::UpVector * 2.0f + EdgeDirectionNormalized * UWorldSevenUtilities::GetTileSize() / 2.0f * GetScale(), 5.0f, FColor::White, false, 5.0f);
    }

    return EdgePosition;
}

The only thing I changed is that I now print the values of the vectors to the screen. Why does printing to the screen suddenly prevent GetSafeNormal from being close to zero?

I desperately need help with this, I have no idea why that is happening.

If I don’t use GetSafeNormal() and implement the normalization myself I don’t have any issues???

The normalization function I used:



float Norm = UKismetMathLibrary::Sqrt(UKismetMathLibrary::Square(Vector.X) + UKismetMathLibrary::Square(Vector.Y) + UKismetMathLibrary::Square(Vector.Z));
FVector VectorNormalized = Norm > tolerance? Vector / Norm : FVector::ZeroVector;