TMap of TMaps

For those who wish to have something that can be accessed by blueprints or for some reason were unable to compile a 2D Map when trying to save it as a UPROPERTY for save games (like in my case for 5.4), use a struct.

So you would have a basic struct like this:

USTRUCT(BlueprintType)
struct FMyMapContainer
{
	GENERATED_BODY();

public:
	FMyMapContainer() {}

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
	TMap<FString, FString> SecondMap;
};

And then your entry map would be declared like this:

UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
TMap<int, FMyMapContrainer> BaseMap;

And you would access your data like this:

BaseMap[Key1].SecondMap[Key2];

Helps with blueprints or with being able to serialize the data. Not sure if you actually can serialize a 2D map directly as that’s why I got compile errors in VS, but this is still the only way you’ll get it to work with blueprints :slight_smile:.

1 Like