What does TEXT() do?

I was following the battery tutorial,and says something on the lines that “the text you put inside TEXT() will show up on the editor as well”.
But where exactly on the editor?! Can you guys show me? (or point me to where the text shows up) :slight_smile:

2 Likes

Hey there, which tutorial are you talking about exactly?

i clicked through Battery Tutorial but i couldnt find any TEXT() reference.

Normally the TEXT() macro is for unicode conversion (see here) of a string literal and its not responsible for showing up anywhere like UE_LOG would print to log/output window.

She says it here C++ Battery Collector: Creating the Spawning Volume | 06 | v4.9 Tutorial Series | Unreal Engine - YouTube from 6:53 to 7:04 :slight_smile:

Sooo…I’m still confused about this :stuck_out_tongue: Why are we using TEXT(“Pickup Mesh”) in the tutorial?
What are we achieving by doing so and what are the ripercussions if we omit it? :slight_smile:

TEXT macro (winnt.h) - Win32 apps | Microsoft Docs Just a macro :slight_smile:
If you need a more detailed explanation please post the relevant lines of code.

1 Like

I apologize,I though I had put it,but I must have forgotten :smiley:

Here’s the line:



PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Pickup Mesh"));


So as my previous question, why are we using TEXT(“Pickup Mesh”) in the tutorial?
What are we achieving by doing so and what are the ripercussions if we omit it?

I’m no expert on this, but internally Unreal gives names to objects when they’re created, like StaticMeshComponent_0 or SkeletalMeshComponent_1254 to enable the internals to reference specific instances of these objects. Here you’re simply telling Unreal that you use a specific name (“Pickup Mesh”) for your component.

It also allows you to find this component by name if required.

Thanks staticvoidlol,also if anyone has more information regarding it I’m all hears :slight_smile:

It is for “automatic” unicode/ansi string constants (IF it is the same as the macro I see whith VS C++).

You could also have gone to the definition of “TEXT” and found out what the macro does.

HTH

I read the definition,but my low programming knowledge doesn’t yet allow me to fully understand :rolleyes:

We are all learning :slight_smile:

What the TEXT macro does is insert a “L” before string literals if we are under a Unicode/Multibyte build and nothing when under ANSI.
All it does is tell the compiler what values to put there.

The end result is that you can use the “TEXT” macro to make it simple to create string literals of whatever character set you are using.

HTH

2 Likes

I see. So in this case used with " CreateDefaultSubobject" I take I should just put it there for everything to work smoothly internally. It will still be quite some time until I get all the knowledge to investigate this deeper (like readying myself the source code),so for now this will do. Thanks :wink:

To simplify it a bit:
You are using the TEXT() macro to make 100% sure the string “Pickup Mesh” is in the correct format.

2 Likes

Thx for that Skynet,it fits even better with the info you guys already gave me, I’ll make a not of this :stuck_out_tongue:

Btw guys,finally found where the stuff you put inside TEXT() while creating components actually displays on the editor :smiley:

The code


CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("BANANAS_FOR_eVERYONE"));

generate the image below. Though Compiling is not enough to make the change appear,you need to create a new instance of the c++ class
So as you can see “BANANAS_FOR_eVERYONE” is actually a UTextRenderComponent :smiley:
(though if you kind of “ovverride it” with “RootComponent = CountdownText;” then it shows RootComponent instead )

Text will just ensure it outputs a TCHAR*, which would be the low level character representation in UE. You can convert a *TCHAR *to *UTF8 *for example using TCHAR_TO_UTF, there are others too.

While looking into this, I also found this line in the coding standard:

So there’s also that!

(Zombie post, but this is the top google result for questions about why to use TEXT in UE4, so I hope this’ll be helpful information for some folks.)

7 Likes