I had a code that works properly in UE4 using UTextRenderComponent to render some text while the game is running.
When I moved to UE5, the text is replaced by a blank rectangle that is of the same size and color of the text, any idea?
TextRenderCompnent works in 5
Did you set it up correctly in code?
Example
header
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Input, meta = (AllowPrivateAccess = "true"))
class UTextRenderComponent* textRenderComp;
in cpp inside of the CDO constructor
textRenderComp = CreateDefaultSubobject<UTextRenderComponent>(TEXT("Text render commp"));
textRenderComp->SetupAttachment(GetRootComponent());
cpp also needs include
#include "Components/TextRenderComponent.h"
It used to work properly in UE4.
But maybe my code has some mistakes that were allowed in 4 and not 5.
Now it renders without the text, instead a rectangle.
In header (in an AActor):
TArray<UTextRenderComponent*>is_TextDumpster;//A hundred component for text rendering in 3d space.
In source file (in AActor constructor):
for (int i = 0; i < 100; i++)
{
//name.
FString string = "is_TextComponent";
string.AppendInt(i);
//creating subobjects.
is_TextDumpster.Add(CreateDefaultSubobject<UTextRenderComponent>(*string));
is_TextDumpster.Last()->SetupAttachment(Root);
is_TextDumpster.Last()->SetRelativeRotation(FRotator(0.f, 180.f, 0.f));
is_TextDumpster.Last()->SetVisibility(true);
}
for (int i = 0; i < 100; i++)
{
//name.
FString string = "is_TextComponent";
string.AppendInt(i);
//creating subobjects.
UTextRenderComponent* txtc = CreateDefaultSubobject<UTextRenderComponent>(*string);
txtc->SetupAttachment(GetRootComponent());
txtc->SetRelativeRotation(FRotator(0.f, 180.f, 0.f));
//txtc->SetText(FText::FromString(string));
txtc->SetVisibility(true);
is_TextDumpster.Add(txtc);
}
I also made the TArray a uproperty in the header so it won’t get garbage collected.
It doesn’t work.
It still renders with the proper color and dimensions of the text, but instead a blank rectangle. Maybe it has to do with the font or something, but I never changed the default font.
Try creating a new font importing a truetype font (ttf), assigning it and see if it persists.
Sometimes symbols from other languages may not register if they are not present in the version of the used font.
I turns out the problem was inherent to UE5 version 5.0
I downloaded 5.2 from GitHub, and built it all was fine.
Thanks for your help.