Unreal Engine

13. 언리얼 MultiMap

CE : 하랑 2026. 2. 8. 16:18

 

언리얼 엔진에서 MultiMap은 일반적인 Map(C++의 TMap 등)과 달리, 하나의 키에 여러 개의 값을 저장할 수 있는 자료구조입니다. 언리얼 C++에서는 기본적으로 TMultiMap이라는 템플릿 클래스로 제공됩니다.

TMultiMap<FString, int32> sMyMultiMap_List;

// 값 추가
sMyMultiMap_List.Add(TEXT("Key1"), 100);
sMyMultiMap_List.Add(TEXT("Key1"), 200);
sMyMultiMap_List.Add(TEXT("Key2"), 300);

// 특정 키에 대한 모든 값 가져오기
TArray<int32> iValues_List;
sMyMultiMap_List.MultiFind(TEXT("Key1"), iValues_List);

// 반복 출력
for (int32 iValue : iValues_List)
{
    UE_LOG(LogTemp, Log, TEXT("Value: %d"), iValue);
}

  • TMultiMap은 키 중복을 허용하기 때문에, Map보다는 std::multimap과 유사합니다.
  • 반복자는 TMultiMap::TConstIterator 또는 TMultiMap::TIterator를 사용하여 모든 요소를 순회할 수 있습니다.
for (auto& Elem : MyMultiMap){
    FString Key = Elem.Key;
    int32 Value = Elem.Value;

    UE_LOG(LogTemp, Log, TEXT("Key: %s, Value: %d"), *Key, Value);
}

'Unreal Engine' 카테고리의 다른 글

16. UClass VS TSubclassOf  (0) 2026.03.15
15. 게임 모드  (1) 2026.03.15
12 . 언리얼 TArray Sort VS StableSort  (0) 2026.02.08
10. FMath  (0) 2026.02.01
9. [언리얼 C++] 멀티캐스트 델리게이트  (0) 2026.02.01