String Formatting for TEXT

What I want to do is easy but I cannot figure it out.

static ConstructorHelpers::FObjectFinder<UStaticMesh> GroundShape(TEXT("StaticMesh'/Game/Shapes/Ground/ground_shape_1.ground_shape_1'"));

The code above is the think I want to achieve. However, it is going to be a dynamic version of it. For instance rather than ground_shape_1, I want the number 1 to be non-static. I want version like ground_shape_1, ground_shape_2, ground_shape_3 and so on. However, I do not know how to format a TEXT.

FString::Printf(TEXT("StaticMesh'/Game/Shapes/Ground/ground_shape_%d.ground_shape_%d'"), i);   

The code above looks fine but FObjectFinder just does not want FString but TChar only.

Any Suggestions?

1 Like

The dereference operator (*) is overloaded on FString to return a pointer to its internal TCHAR buffer.

This should sort you out:

*FString::Printf(TEXT("StaticMesh'/Game/Shapes/Ground/ground_shape_%d.ground_shape_%d'"), i);
1 Like

Thank you sir. I need to improve my C++ skills.

Oh, that one’s a Unreal Engine oddity :slight_smile:

I’ve never seen another string class that does that (you usually either have to call a function to get the buffer, or they overload the cast operator to allow it to happen implicitly).