TextRender Component Invisible

Hey all,

I created a Text render component and attached it to a spring arm on my 2d character. My idea was since this is a multiplayer game, when they die to have the text become visible and show a message kinda in 3d space. I know theres other ways using textures and whatnot, but theres a reason im using the text.

Anyways, after creating the component in code and going to my blueprint derived off the class, the text renderer is shown attached correctly, etc in my component list, and I can edit all of the details. But no text ever gets rendered.

This happens regardless of if I set visibility to true or not. Fonts are all set fine and everything seems great. If I create a new copy of a text renderer in the blueprint by hand, with all the same settings as the one in code, it works fine.
Now, I could just change it in the BP, but then I’d have to change it for many different character BPs as I have separate ones for different classes, and the text needs to be common functionality.

The code is simple:

   TextBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("TextBoom"));
	TextBoom->AttachTo(RootComponent);
	TextBoom->TargetArmLength = 100.0f;
	TextBoom->SocketOffset = FVector(0.0f, 0.0f, 75.0f);
	TextBoom->bAbsoluteRotation = true;
	TextBoom->RelativeRotation = FRotator(0.0f, -90.0f, 0.0f);

	// Setup our Text Renderer
	TextComponent = CreateDefaultSubobject<UTextRenderComponent>(TEXT("TextComponent"));
	TextComponent->AttachTo(TextBoom, USpringArmComponent::SocketName);
	TextComponent->SetVisibility(true);
	TextComponent->SetHorizontalAlignment(EHorizTextAligment::EHTA_Center);
	TextComponent->VerticalAlignment = EVerticalAlignment::VAlign_Center;
	TextComponent->SetText("TEST");

Hi shigan
I’ve got the same problem here. I have an actor that has dynamically added UTextRenderComponents with dynamically set texts. The creation code is similar to yours. Now, when I hit play, no text is rendered, although the components are added correctly in the correct place, rotation etc.

However, I discovered that if I edit the component’s rotation value (my components are rotated by 180, 90, 0), the texts are displayed all of a sudden.

I took the following steps:

  • Pause game
  • Press F8
  • Find actor in World Outliner
  • Select TextRenderComponent
  • Edit one of component’s rotation values (e.g. roll)
  • (text is displayed already, but rotated wrong)
  • Set rotation value back to original value
  • If I unpause game, texts are (still) displayed

What’s strange is that all TextRenderComponents of the actor (there are multiple components on one actor in my case) are suddenly displayed, although I only edited one component’s rotation value.

Looks like a bug to me. Any help appreciated!

Hi shigan

I don’t know if this problem is still an issue for you. I just wanted to let you know that I opened a bug report for my issue (which is probably the same as yours): TextRenderComponent not displaying when added at runtime

The problem you are having is that you use CreateDefaultSubobject, which is call that should only be done for defaults object, that is components created in the constructor. To dynamically create a text render component elsewhere, you need to use ConstructObject or one of the equivalent calls. Here is an example extracted from my game, where I dynamically spawn TextRender components:

UTextRenderComponent* TextRender = ConstructObject<UTextRenderComponent>(UTextRenderComponent::StaticClass(), this, FName(*(FString::Printf(TEXT("Debug Text Component %i"), (int32)i))));

		TextRender->SetMobility(EComponentMobility::Movable);
		TextRender->SetHorizontalAlignment(EHTA_Center);
		TextRender->SetCastShadow(false);
		TextRender->bCastDynamicShadow = false;
		TextRender->bAffectDynamicIndirectLighting = false;
		TextRender->SetMaterial(0, mTextMaterial);
		TextRender->AttachParent = mSplineComponent;

		TextRender->SetWorldSize(mDebugTextSize);
		TextRender->SetText(FString::Printf(TEXT("Segment %i (Speed %i)"), (int32)i, (int32)mSegments[i].mSpeed));
		TextRender->SetWorldLocation(mSplineComponent->GetWorldLocationAtSplinePoint(i) + FVector(0.0f, 0.0f, 10.0f));