# How does one correctly expose a function to blueprints with a TMap\<anything, UInterface\> in C++?

**URL:** <https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556>\
**Category:** C++\
**Tags:** unreal-engine, UE5-0, question, CPP\
**Created:** [July 20, 2022, 5:29pm UTC](https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556 "2022-07-20T17:29:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ragnaraven](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ragnaraven](https://forums.unrealengine.com/u/Ragnaraven)\
**Post date:** [July 20, 2022, 5:29pm UTC](https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556/1 "2022-07-20T17:29:37Z")

</div>

**How do you correctly create a Blueprint exposed TMap with a Uinterface as the value type in C++?**

Here is what I want to do in C++:  
Here is the parameter I want to add in C++ but working in BP:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/d/5/dd52f1cef2870ce69a47b1b7c1fedcad2c78c3df.png)  
Here is the simple interface:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/c/d/fcd5a9370a0bea8d48c2bc1699c0853481fe14bd.png)

Here is my attempt at the function in C++:

```auto
	UFUNCTION(BlueprintCallable)
	void AddColumn(TMap<FName, TScriptInterface<ITUGGDebugTextable>>& Column);

```

Here is a working C++ version of the BP interface:

```auto
// This class does not need to be modified.
UINTERFACE(MinimalAPI, Blueprintable)
class UTUGGDebugTextable : public UInterface
{
	GENERATED_BODY()
};

/**
 * 
 */
class TUGGCORERUNTIME_API ITUGGDebugTextable
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Errors")
	void SetText(const FText& Text);
};

```

Here is an example of the error I get

```auto
  [2/2] Compile Module.TUGGCoreRuntime.gen.cpp
XXX\TUGGCore\Intermediate\Build\Win64\UnrealEditor\Inc\TUGGCoreRuntime\GameplaySettingsDebugUIHelper.gen.cpp(20): error C3203: 'TScriptInterface': unspecialized class template can't be used as a template argument for template parameter 'InValueType', expected a real type
 XXX\TUGGCore\Intermediate\Build\Win64\UnrealEditor\Inc\TUGGCoreRuntime\GameplaySettingsDebugUIHelper.gen.cpp(23): error C2664: 'void UGameplaySettingsDebugUIHelper::AddColumn(TMap<FName,TScriptInterface<ITUGGDebugTextable>,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>> &)': cannot convert argument 1 from 'TMap<FName,int32,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>>' to 'TMap<FName,TScriptInterface<ITUGGDebugTextable>,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>> &'
          with
          [
              InKeyType=FName,
              InValueType=TScriptInterface<ITUGGDebugTextable>
          ]
          and
          [
              InKeyType=FName,
              InValueType=int32
          ]
          and
          [
              InKeyType=FName,
              InValueType=TScriptInterface<ITUGGDebugTextable>
          ]
  XXX\TUGGCore\Source\TUGGCoreRuntime\Public\Debug\GameplaySettingsDebugUIHelper.h(21): note: see declaration of 'UGameplaySettingsDebugUIHelper::AddColumn'

```

Strangely, this builds just fine!

```auto
	UFUNCTION(BlueprintCallable)
	void AddColumn(TArray<TScriptInterface<ITUGGDebugTextable>>& Column);

```

So why is TMap different than TArray?

I have tried every solution I can think of and every solution I can find online. Before I file a suspected bug report, I am hoping a community member can enlighten me. It appears the generated CPP is invalid, yet, somehow I can do this exact thing in BP. There is an old bug here: [Array of Interfaces, blueprintable c++ function parameter - #16 by UnrealEverything](https://forums.unrealengine.com/t/array-of-interfaces-blueprintable-c-function-parameter/334489/16) I suspect this is related if my code is good (which it may not be).

**How do you correctly create a Blueprint exposed TMap with a Uinterface as the value type?**

---

<div class="post-metadata">

**Author:** ![Ragnaraven](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ragnaraven](https://forums.unrealengine.com/u/Ragnaraven)\
**Post date:** [July 20, 2022, 5:55pm UTC](https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556/2 "2022-07-20T17:55:47Z")

</div>

Potential solution. Works but I would prefer a Map of the correct type. I am going to leave this question open to see if there are better ways in case anyone else in the future makes the BP → C++ jump.

```auto
	UFUNCTION(BlueprintCallable)
	void AddColumn(const FName ColName, const TMap<FName, UObject*>& Column);

```

---

<div class="post-metadata">

**Author:** ![UnrealEverything](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnrealEverything](https://forums.unrealengine.com/u/UnrealEverything)\
**Post date:** [July 21, 2022, 6:19am UTC](https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556/3 "2022-07-21T06:19:38Z")

</div>

Interesting, havn’t looked too deep into UE5 yet so cannot say for sure. What you could also try to do is wrap the `TScriptInterface<ITUGGDebugTextable>` in a `USTRUCT`. That way you would get to use your interface instead of just `UObject*`. If it’s actually caused by bad code generation from UnrealHeaderTool the `CustomThunk` solution should probably also work.

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [July 21, 2022, 8:41am UTC](https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556/4 "2022-07-21T08:41:38Z")

</div>

Definitely looks like a bug.  
The generated code for VM-conversion omits the TScriptInterface specialization for TMap, but not for TArray :

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/d/7/cd78f37f89eb02c2a2c9663c8cdd52a6e73f8bb1.png)

UnrealHeaderTool has some hardcoded handling for TScriptInterface within TArray. It doesn’t handle them in TMap or TSet :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/a/c/baca63654eea2a73f222377a1870f3f1b1b5a895.png)

---

<div class="post-metadata">

**Author:** ![Ragnaraven](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ragnaraven](https://forums.unrealengine.com/u/Ragnaraven)\
**Post date:** [July 21, 2022, 12:07pm UTC](https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556/5 "2022-07-21T12:07:23Z")

</div>

I will investigate that. Thank you for your solution.

---

<div class="post-metadata">

**Author:** ![Ragnaraven](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ragnaraven](https://forums.unrealengine.com/u/Ragnaraven)\
**Post date:** [July 21, 2022, 12:09pm UTC](https://forums.unrealengine.com/t/how-does-one-correctly-expose-a-function-to-blueprints-with-a-tmap-anything-uinterface-in-c/609556/6 "2022-07-21T12:09:08Z")

</div>

Thank you, sir. I will submit a report that refers this answer.
