How to combine 3 TCHAR* elements

I’m trying to combine three THCAR* elements into a single file path so I can load assets based on which level set I choose. Could someone help with this?

This is what I have currently:

LevelTiles::LevelTiles(ULevelGeneratorSettings* _settings)
{
	TCHAR* _levelFolder = TEXT("1_Prison");
	TCHAR* _bluePrint   = TEXT("/BluePrints/LevelTiles/TILE_WALL_3_T_CORNER.TILE_WALL_3_T_CORNER_C'");

	TCHAR* _fullPath = TEXT("Blueprint'/Game/_ProjectAssets/Level_Assets/");

	_stprintf(_fullPath, _T("%s%s"), _levelFolder, _bluePrint);

	_levelTiles.push_back(LevelTile(_fullPath));
}

However, the engine crashes when it gets to the ‘stprintf’ line with an access violation.

Why you use TCHAR* insted of FString?

_fullPath is a pointer to string literal, it’s read-only memory and you can’t write to it, attempting to do so will crash the program, which is exactly what happens when _stprintf attempts to write to _fullPath.

As @anonymous_user_f5a50610 said you should be using FString instead of attempting to manipulate strings as TCHAR*, something like this:

FString _levelFolder = TEXT("1_Prison");
FString _bluePrint = TEXT("/BluePrints/LevelTiles/TILE_WALL_3_T_CORNER.TILE_WALL_3_T_CORNER_C'");
FString _fullPath = _levelFolder + _bluePrint;

Fair enough, thank you for the explanation.

To answer what asked, the reason I am using TCHAR* elements is because of the “StaticLoadObject” function, which takes in a TCHAR* parameter. I’m using this to load and spawn Blueprints at runtime.

Many thanks.

You can get a TCHAR* from an FString by dereferencing, e.g.

FString myStr(TEXT("Something"));
const TCHAR* myStrPtr = *myStr;

Awesome, I managed to update my code and spawn the blueprints. Thanks again for your help.