How to have a templated/value agnostic TMap as a parameter in Unreal

I want to set up a universal function for a bunch of TMaps I’m using. They all share int32s as keys but they have various of my own structs as values.

I read that Unreal doesn’t like templates for reflection purposes so is there a way I can have a function that can take any TMap with hash type int32 and perform the necessary operations on it?

I know I can do overloaded functions but I’m lazy and curious.

It’s not like it “doesn’t like”, it simply does not support it, specially that it compile time feature of C++ and don’t do anything in run time. If you not plan to use function in blueprints it’s ok to use templates, i mean lot of UE4 classes using them.

For bluepritns you use CustomThunk to make wildcard pins

https://forums.unrealengine.com/community/community-content-tools-and-tutorials/27351-tutorial-how-to-accept-wildcard-structs-in-your-ufunctions

you can also make U2KNode

you can also try to work around things with UMapProperty

It’s not like it “doesn’t like”, it simply does not support it, specially that it compile time feature of C++ and don’t do anything in run time. If you not plan to use function in blueprints it’s ok to use templates, i mean lot of classes using them.

For bluepritns you use CustomThunk to make wildcard pins

https://forums.unrealengine.com/community/community-content-tools-and-tutorials/27351-tutorial-how-to-accept-wildcard-structs-in-your-ufunctions

you can also make U2KNode

you can also try to work around things with UMapProperty

https://docs.unrealengine.com/en-US/API/Runtime/CoreUObject/UObject/UMapProperty/index.html

And you can access UProperties via UClass (and UStruct too)

I’m a little unclear about the architecture; do you mean that as long as the function that takes a template as a parameter is not blueprintcallable itself then templates are okay?

Reflection system is one that does not support C++ templates, so as long as it’s not UFUNCTION() UE4 won’t have issue with it and again UE4 classes themselves use those, like SpawnActor, lot of get function got auto cast templates. You also have lot of function overloads and operator overloads, another thing that is not supported by reflection system.

Adding things to reflection system except few exceptions (UObject classes, UObject pointer properties, functions for dynamic delegates) is always optional, UE4 won’t see those variables or functions but they usable in C++ and UE4 should not have issue with it. Ofcorsse you need to avoid that if you can but, in case of template functions this should not be a big deal

If that function is needed to be used in blueprint you need to make special function that will call templated function, thats how UE4 also deals with stuff outside of reflection system… i mean oyu got entire UI system UMG made as a wrapper to Slate just because Slate is made to work outside of UObject envriament

Thank you for the further clarification, the architecture makes sense now. I’m new to both UE4 and programming so it’s still a bit of a strange land in terms of what is possible and what is not.

Looking forward to making some nice lazy functions.