Apparently, the font also needs a material. The following material has parameters that can be changed at runtime. For that you need a dynamic material instance. You can look into that if you’re interested. For now, we’re just gonna slap the material on our font:
In the editor, right click the material > copy reference. Use this path for your .cpp constructor.
#include "ConstructorHelpers.h"
ConstructorHelpers::FObjectFinder<UMaterial> FontMaterial(TEXT("Material'/Game/AuraTD/Fonts/AldrichMaterial.AldrichMaterial'"));
I then put the Succeeded()
check inside my font asset check. If the font doesn’t load, there’s no reason to do anything with the material. TRC
is of course my text render component.
if (TextRenderFont.Succeeded())
{
TRC->SetFont(TextRenderFont.Object);
TRC->SetTextRenderColor(FColor::Blue);
if (FontMaterial.Succeeded())
{
TRC->SetTextMaterial(FontMaterial.Object);
}
}