# Inserting a variable in the TEXT Macro

**URL:** <https://forums.unrealengine.com/t/inserting-a-variable-in-the-text-macro/371883>\
**Category:** UI\
**Tags:** Variable, text, unreal-engine, UE4, CPP, question\
**Created:** [September 28, 2016, 3:04pm UTC](https://forums.unrealengine.com/t/inserting-a-variable-in-the-text-macro/371883 "2016-09-28T15:04:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![A7E7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@A7E7](https://forums.unrealengine.com/u/A7E7)\
**Post date:** [September 28, 2016, 3:04pm UTC](https://forums.unrealengine.com/t/inserting-a-variable-in-the-text-macro/371883/1 "2016-09-28T15:04:02Z")

</div>

Hey guys,

I’m simply trying to name a component with a variable.

```
   for (int i = 0; i < 5; ++i)
    {
    	UStaticMeshComponent* tmp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh" + i));
        ...
    }
    
   // or TEXT("Mesh%d", i)

```

I know this is somehow basic, but I really can’t figure it out. Does anyone know a way to do this?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![PasteDog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PasteDog](https://forums.unrealengine.com/u/PasteDog)\
**Post date:** [September 28, 2016, 3:37pm UTC](https://forums.unrealengine.com/t/inserting-a-variable-in-the-text-macro/371883/2 "2016-09-28T15:37:42Z")

</div>

Hey A7E7,

You could try something like:

```
CreateDefaultSubobject<UStaticMesh>(*FString("Name" + FString::FromInt(i)));

```

Also take a look at this link for more information:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Hope this helps 🙂  
Elias

---

<div class="post-metadata">

**Author:** ![A7E7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@A7E7](https://forums.unrealengine.com/u/A7E7)\
**Post date:** [September 28, 2016, 3:44pm UTC](https://forums.unrealengine.com/t/inserting-a-variable-in-the-text-macro/371883/3 "2016-09-28T15:44:55Z")

</div>

Thanks a lot! I actually tried it like this but without the \* 😑

---

<div class="post-metadata">

**Author:** ![PasteDog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PasteDog](https://forums.unrealengine.com/u/PasteDog)\
**Post date:** [September 28, 2016, 3:54pm UTC](https://forums.unrealengine.com/t/inserting-a-variable-in-the-text-macro/371883/4 "2016-09-28T15:54:44Z")

</div>

Yea it is because you need to convert the FString to FName.  
Np! 🙂
