Putting variables into TEXT macro

static ConstructorHelpers::FObjectFinder Mesh(TEXT(“Content/Meshes/” + Name));

Trying to load meshes dynamically but it seems like the TEXT macro only takes hardcoded strings or something?

FObjectFinder takes TCHAR (which char*) same as TEXT technically, which doesn’t support + operator (it doesn’t support string appending to begin with), it the closest you can get for native support of string in C and C++ as both does not really support strings natively, instead it’s a array of char type which is single string character(char* points to array), with special character /O at the end to indicate end of string.

FString is UE4 implmentation of String support in C++ (alternatively C++ standard libery implementation which you should avoid using in UE4 std::string), it manages TCHAR array. You can access TCHAR array (which formally is TCHAR* pointing to array) inside any FString using * operator, so one way of doing it like this:

FString PathName = FString(TEXT("Content/Meshes/") + Name);
static ConstructorHelpers::FObjectFinder Mesh(*PathName));

Thanks, I figured out I can also do:

FString Path = "/Game/Meshes/" + Name;
	
	const TCHAR* CPath = *Path;
	
	UStaticMesh* Mesh = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, CPath));
1 Like

Can convert FString to TCHAR by doing the following:

FString Path = "/Game/Meshes/" + Name;
	
	const TCHAR* CPath = *Path;
	
	UStaticMesh* Mesh = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, CPath));