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.
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.
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: