Minor bug in one of the AHUD.DrawText() methods

The following method:

Seems to be incorrect with respect to how the text is positioned and with how it is setup. First I don’t quite get why “const float Y = Canvas->ClipY/3.0f - YL/2.0f + Position.Y;” is dividing by 3? I assume this is trying to move the origin to the center of the screen, so I am guessing that 3.0f should be a 2.0f. Also the passed in color is not used since the FCanvasTextItem created is also not used and the text is drawn using “Canvas->DrawText(TextFont, Text, X, Y, FontScale.X, FontScale.Y);” instead of “Canvas->DrawItem( TextItem );”.

I am guessing the function should look like this:

void AHUD::DrawText(const FString& Text, FVector2D Position, UFont* TextFont, FVector2D FontScale, FColor TextColor)
    float XL, YL;
    Canvas->TextSize(TextFont, Text, XL, YL);
    const float X = Canvas->ClipX/2.0f - XL/2.0f + Position.X;
    const float Y = Canvas->ClipY/2.0f - YL/2.0f + Position.Y;
    FCanvasTextItem TextItem( FVector2D( X, Y ), FText::FromString( Text ), TextFont ? TextFont : GEngine->GetMediumFont(), FLinearColor( TextColor ) );
    TextItem.Scale = FontScale;
    Canvas->DrawItem( TextItem );


Yup, I think you’re right there is at least a few bugs in there. Upon discussion we’re actually having a bit of a time figuring out what we think the function is supposed to be accomplishing. I’ve put a bug report in for someone to investigate it and possibly make it go away.

For interest I chased back through perforce history and the divide by 3 has been in there since the function was written back in the UE3 days.

Hah, interesting. Perhaps it was moving the origin to the center along X, but bottom third of the screen on Y? Kind of like where “PAUSED” appears.

Edit: Actually it would be the upper third since 0 is at the top.

Or it splits the screen into three alignments - Centre, Left Align and Right Align, then offsets each of these according to values passed in?

Heh, I already made a pull request on GitHub a few days ago as I ran into the same problem.
I wasn’t able to test it though, so if anyone has anything to add, feel free to do so!