Can't get DrawText to render to the screen

What am I missing guys… I have managed to get the DrawHUD to run repeatedly:


AMainHUD::AMainHUD(const class FPostConstructInitializeProperties& PCIP)
	:	Super(PCIP)
{
	Points = PCIP.CreateDefaultSubobject<UHUDElementComponent>(this, TEXT("HUDElementComponent"));
	ConstructorHelpers::FObjectFinder<UFont> FontObject(TEXT("Font'/Game/Fonts/PointsFont.PointsFont"));
	if (FontObject.Object)
	{
		Points ->Font = FontObject.Object;
	}

}

void AMainHUD::DrawHUD()
{
	DrawText(TEXT("Hi"), FColor(100, 100, 100, 0), 200.0f, 200.0f, NULL, 1.0f, false);
}

but the DrawText is not drawing to the screen… What might I be doing wrong?

My GameMode has AMainHUD defined as its class and I guess that’s working because it is correctly running the DrawHUD event


Draw2DLine(0, 100, 100, 200, FColor(100, 100, 100, 0));

is working but still no cigar on the DrawText?

I’ve also tried:


void AMainHUD::DrawHUD()
{
	FString string = "HI THERE";
	DrawText(string, FVector2D(10.0f, 10.0f), Points->Font, FVector2D(1.0f, 1.0f), FColor(100, 100, 100, 0));
}

I’ve also tried:


DrawText(string, FVector2D(100.0f, 100.0f), Points->Font, FVector2D(1.0f, 1.0f), FColor(1.0f, 1.0f, 1.0f, 0.0f));

and


DrawText(string, FVector2D(100.0f, 100.0f), Points->Font, FVector2D(1.0f, 1.0f), FColor(1.0f, 1.0f, 1.0f, 1.0f));

For a number of your examples, it looks like your FColor is completely transparent (alpha = 0). Try FColor(255, 255, 255, 255) and see if that makes your text visible. :slight_smile:

If you would like to follow along with an example, there is thisCoding a Canvas HUDvideo. The DrawText line from it is:

DrawText(TEXT(“GAME OVER”), FColor::White, (ScreenDimensions.X - GameOverSize.X) / 2.f, (ScreenDimensions.Y - GameOverSize.Y) / 2.f, HUDFont);

Basically, the parameters used there are:

void DrawText
(
const FString & Text,
FLinearColor TextColor,
float ScreenX,
float ScreenY,
class UFont * Font,
float Scale,
bool bScalePosition
)

Does that example help at all?

You know what’s funny… The Draw2DLine actually gets drawn when alpha is at 0.0f… so I thought i’d try it both ways for the DrawText… it originally started off as a typo… However, no it doesn’t make a difference.

I’m at work at the moment, but when I get home:

  • I’ll try the 255… I thought it would be a range from 0 - 1 for alpha
  • I’ll try to pick the different overload you have stated

Thanks in advance!

Are you sure that your font object is getting properly? Try to toss a breakpoint on this line in your code:

[FONT=Lucida Console]Points ->Font = FontObject.Object;

If the breakpoint doesn’t get triggered when you play the game, you should know what the problem is. That’s the only thing I can really think of; your DrawText calls look OK otherwise to me.

Thanks,

I must have been a complete noob yesterday…


DrawText(TEXT("HI THERE"), FColor(255.0f,255.0f,255.0f), 10.0f, 10.0f, Points->Font, 1.0f, false);

All working now ta.

By the way if you want to use 0 - 1 range, it is FLinearColor