Inserting a variable in the TEXT Macro

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!

Hey A7E7,

You could try something like:

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

Also take a look at this link for more information:

Hope this helps :slight_smile:

Thanks a lot! I actually tried it like this but without the * :expressionless:

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