# Error when adding item to a TMap: "User-defined literal operator not found"

**URL:** <https://forums.unrealengine.com/t/error-when-adding-item-to-a-tmap-user-defined-literal-operator-not-found/484927>\
**Category:** C++\
**Tags:** tmap, unreal-engine, question, CPP\
**Created:** [June 15, 2021, 10:12am UTC](https://forums.unrealengine.com/t/error-when-adding-item-to-a-tmap-user-defined-literal-operator-not-found/484927 "2021-06-15T10:12:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Signified.Mark](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Signified.Mark](https://forums.unrealengine.com/u/Signified.Mark)\
**Post date:** [June 15, 2021, 10:12am UTC](https://forums.unrealengine.com/t/error-when-adding-item-to-a-tmap-user-defined-literal-operator-not-found/484927/1 "2021-06-15T10:12:23Z")

</div>

Hi,

new to programming with C++ and struggling to create a TMap with Fstring as Key and AnimMontage as value.

I’m trying to add the AnimMontage 104\_montage and the error “User-defined literal operator not found” appears.

I’ve attached my cpp and .h files below.

Any help would be apprecited.  
Thanks,  
Mark

AnimTMap.H

```
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "AnimTMap.generated.h"

UCLASS()
class MYPROJECT_API AAnimTMap : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AAnimTMap();

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TMap<FString, UAnimMontage*> AnimationMap;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

};

```

AnimTMap.cpp

```
#include "AnimTMap.h"

// Sets default values
AAnimTMap::AAnimTMap()
{
 	// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AAnimTMap::BeginPlay()
{
	Super::BeginPlay(); 
	AnimationMap.Add("hello",104_montage);
}

// Called every frame
void AAnimTMap::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

```

---

<div class="post-metadata">

**Author:** ![CtnDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ctndev/32/1133321_2.png) [@CtnDev](https://forums.unrealengine.com/u/CtnDev)\
**Post date:** [June 15, 2021, 9:33pm UTC](https://forums.unrealengine.com/t/error-when-adding-item-to-a-tmap-user-defined-literal-operator-not-found/484927/2 "2021-06-15T21:33:57Z")

</div>

You need to set your referance properly to `104_montage` c++ wouldnt know if you are referencing an asset from the editor. For that purpose you need to use `ConstructorHelpers::FObjectFinder`   
  
First go and copy referance from editor ( **since I dont have it I will go over some example.** )

 ![341562-zls1odu7ic.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/1/e/51e2453d704a876d402cf9fc92751fa2e963c925.png)

This will give you as copy something like below :   
  
`AnimMontage'/Game/Characters/XYZ_AnimMontage.XYZ_AnimMontage'`  
  
with that copy you will do as follows

```
include "UObject/ConstructorHelpers.h"
...
...
...
void AAnimTMap::BeginPlay()
 {
     Super::BeginPlay();
     static ConstructorHelpers::FObjectFinder<UAnimMontage> AnimMontageRef(TEXT("AnimMontage'/Game/Characters/XYZ_AnimMontage.XYZ_AnimMontage'"));
	if (AnimMontageRef.Succeeded())
		AnimationMap.Add("hello",AnimMontageRef.object);     
 }

```

If you have any concerns you can look up samples of `ConstructorHelpers::FObjectFinder`

---

<div class="post-metadata">

**Author:** ![Signified.Mark](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Signified.Mark](https://forums.unrealengine.com/u/Signified.Mark)\
**Post date:** [June 16, 2021, 12:25pm UTC](https://forums.unrealengine.com/t/error-when-adding-item-to-a-tmap-user-defined-literal-operator-not-found/484927/3 "2021-06-16T12:25:54Z")

</div>

Thanks for the response.

So when I try to access the TMap AnimationMap in a blueprint the error “FObjectFinders can’t be used outside of constructors” appears.

Fatal error: [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp] [Line: 3287] FObjectFinders can’t be used outside of constructors to find /Game/Animations/Animations/104\_Montage.104\_Montage

UE4Editor\_CoreUObject  
UE4Editor\_MyProject\_7751!AAnimTMap::BeginPlay() [C:\Users\Administrator\Documents\Unreal Projects\MyProject\Source\MyProject\Private\AnimTMap.cpp:18]  
UE4Editor\_Engine  
UE4Editor\_Engine  
UE4Editor\_Engine  
UE4Editor\_Engine  
UE4Editor\_Engine  
UE4Editor\_UnrealEd  
UE4Editor\_UnrealEd  
UE4Editor\_UnrealEd  
UE4Editor\_UnrealEd  
UE4Editor\_UnrealEd  
UE4Editor\_UnrealEd  
UE4Editor\_UnrealEd  
UE4Editor\_UnrealEd  
UE4Editor  
UE4Editor  
UE4Editor  
UE4Editor  
UE4Editor  
kernel32  
ntdll

So after a bit of googling I came up with the following solution to use LoadObject instead.

```
UAnimMontage* MontageHello = LoadObject<UAnimMontage>(NULL, TEXT("AnimMontage'/Game/Animations/Animations/104_Montage.104_Montage'"));

AnimationMap.Add("hello", MontageHello);

```

Thanks for leading me down the right path and if there is a better solution please let me know.
