How to load a Font.uasset and use it for FSlateFontInfo

I wanted to use the .uasset file and not .ttf, and I found a way how to do it:

Inside .h file I added:

UObject* serifFont;
FSlateFontInfo info;

Then inside .cpp:

void SlateMessageWidget::Construct(const FArguments& InArgs, FString message, FString fontFamily, int fontSize) {
	serifFont = LoadObject<UObject>(nullptr, TEXT("/Game/Fonts/PT_Serif/PT-Serif"));
	info = FSlateFontInfo(serifFont, fontSize, FName(fontFamily));

And you can use “info” for the font:

.Font(info)
2 Likes