I very much like the idea of new type promotion in UE5 blueprints, and I’d like to introduce it to my own C++ classes. I’m trying to figure out a way to make a Registry type of structure - kinda like Windows’ Registry: taking in bools, ints, floats, doubles or FStrings. If there was only about C++, there’d be no problem, just use templates, but when it comes to programming classes that should be Blueprint-Friendly, that’s somewhat a problem, since c++ templates aren’t available for UFUNCTIONs. I don’t want to introduce 5 different nodes for each type, and instead I want to have one node that can be type promoted, just like math nodes. Is there a way to approach this without editing the engine source?
I get the impression this is a bit of a PITA but you can (in principal) make UFUNCTIONs that take wildcard inputs. Have a look at BlueprintSetLibrary.h
- note the use of CustomThunk
in the declaration, and DECLARE_FUNCTION(exec<functionname>)
for the actual generic code that executes. You can also search the engine source for CustomThunk
if you need more examples of its usage (I’m afraid the docs won’t help much). This forum post may or may not help: [Tutorial] How to accept wildcard structs in your UFUNCTIONs
Thanks, I’ll look into it. From what I’ve seen in BlueprintTypePromotion.h and .cpp, type promotion as a feature is pretty badly hardcoded to only accept predefined math functions (multiply, divide, add, etc.). I’m gonna see if the wildcard trick works.