TArray::Num returning incorrect values

TArray::Num is returning incorrect values for me, and the returned values seem to be influenced by recently used functions. I’m using 4.9.2.

As an example, here is some code with comments detailing the expected results and the incorrectly returned results.

TArray<float> TestArray;
TestArray.Add(20.f);
TestArray.Add(10.f);
TestArray.Add(12.f);

// Line below should cause the output log to say that the number of elements in the array is 3.000000, but the output log actually says 0.000000.  
UE_LOG(LogTemp, Warning, TEXT("Number of elements in TestArray is %f"), TestArray.Num());

// Output log correctly says that TestArray[0] is 20.000000.  
UE_LOG(LogTemp, Warning, TEXT("TestArray[0] is %f"), TestArray[0]);

// Using TestArray.Num() now causes the output log to say that the number of elements in the array is 20.000000, even though it should be 3.000000.  
UE_LOG(LogTemp, Warning, TEXT("Number of elements in TestArray is %f"), TestArray.Num());

// Output log correctly says that TestArray[1] is 10.000000.  
UE_LOG(LogTemp, Warning, TEXT("TestArray[1] is %f"), TestArray[1]);

// Using TestArray.Num() now causes the output log to say that the number of elements in the array is 10.000000, even though it should be 3.000000.  
UE_LOG(LogTemp, Warning, TEXT("Number of elements in TestArray is %f"), TestArray.Num());

This may be unrelated, but you’re using the %f formatter with an int32 value, do you still get a zero value when using %d?

You’re right, using %d gives the expected value. I thought %f was also acceptable since it compiled fine, but now I know that’s not correct. Thanks for the correction.