Logging values gets me this error

You’re trying to print an int with string formatting it seems.

Try this instead:

         if (GEngine) {
             GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Number in the world: %d"), iNumberOfBasicUnits);
         }

However I’d recommend using UE_LOG instead, but it won’t print to screen, it’ll print into your output log, like so:

         if (GEngine) {
            UE_LOG(LogTemp, Warning, TEXT("Number in the world: %d"), iNumberOfBasicUnits);
         }

Reference this documentation: