How to initialize static TMap?

This snippet compiled for me. Will report back if it works in real-time.

static TMap<FString, int32> TestVar = {
	{"5", 5},
	{"3", 3}
};

Update 1

  1. has made a [nice wiki-post][1] for this.
  2. My previous snippet seemed to somehow work.

**Full code**

Header file:

UCLASS(Abstract, Blueprintable)
class PROT_API AYourClass: public AActor
{
	GENERATED_BODY()
	
public:	
	AYourClass();

protected:
	static const TMap<FString, int32> TestVar;
};

Source file:

const TMap<FString, int32> AYourClass::TestVar = {
  {"5", 5},
  {"3", 3}
};

AYourClass::AYourClass()
{
	bAutoDestroyWhenFinished = true;

	for (const auto& Entry : TestVar)
	{
		UE_LOG(LogTemp, Warning, TEXT("-- %d"), Entry.Value);
	}
}

282251-capture.png


**Update 2**
I do understand it is not exactly what question is about yet it might help other people.
6 Likes