Material instance needs to be created first. Theres a function in any primitive component (mesh etc.), to create and override material instance, it return UMaterialInstanceDynamic (create variable for that, in my case is MatInst) in which you can edit parameters:
Look there for a little info on CanvasRenderTarget. I am planning to use this as soon as I get to implementing a proper hud in my game.
Anyway, now I am drawing my materilaized text with TextRenderActor, it is quite easy if you tie it to your camera.
static ConstructorHelpers::FObjectFinder<UMaterial> MatFinder(TEXT("Material'/Game/Materials/Font/TextMaterial_Glow.TextMaterial_Glow'"));
if (MatFinder.Succeeded())
{
Material = MatFinder.Object;
MaterialInstance = UMaterialInstanceDynamic::Create(Material, this);
//Setting a font parameter of a dynamic material instance crashes the game when invoked in a constructor
//using default font parameter until onconstruction
//DamageTextMaterialInstance->SetFontParameterValue("Font", DamageTextFont, 0);
MaterialInstance->SetScalarParameterValue("Glow amount", CurrentGlowAmount);
MaterialInstance->SetScalarParameterValue("Opacity", CurrentOpacity);
}
else
{ //use empty PCIP material (idk what to do, this is just a stub)
MaterialInstance = new UMaterialInstanceDynamic(PCIP);
}
TextRenderComponent = PCIP.CreateDefaultSubobject<UTextRenderComponent>(this, TEXT("TextRenderComponent"), true);
TextRenderComponent->SetMobility(EComponentMobility::Movable);
/* Set location and rotation omitted... */
TextRenderComponent->TextMaterial = MaterialInstance;
TextRenderComponent->TextRenderColor = GlowColor;
TextRenderComponent->Font = Font;
TextRenderComponent->Text = FString("");
I am not entirely sure what exactly TextRenderColor does (I don’t need textures for my text), but here is a link with some textured text.