Not sure, but you could probably make a class that accepts a class UPROPERTY, and go from there, maybe using the template internally from the class “parameter”. Kinda how the “Spawn Actor With Class” blueprint node works, where you specify a class.
Unfortunately, templated function support is pretty limited at the moment. We’re looking to fix this up in the next few months, and make a generic solution for wildcard parameters, but for now, they have to be handled at the node level. We have support for a wildcard pin type (UEdGraphSchema::PC_Wildcard), which we currently use to get template-like functionality for array functions. You can see how we implement it in UK2Node_CallArrayFunction. The gist is that when you connect something to a wildcard slot, we propagate that type to the rest of the wildcard dependent pins. Under the hood, we pass-by-reference, and use the CustomThunk keyword in order to write our own thunk-layer and read the pointer off the stack and coerce the type.
You could do something similar, but much less invasive, if you made your own subclass of UK2Node_CallFunction, and then allocated a wildcard parameter. Then, in NotifyPinConnectionListChanged(), if the pin that was connected was a wildcard, you could search for an appropriate UFunction for your type, and then call UK2Node_SetFromFunction. That’s not purely templated, but would allow you get a similar effect!
Is there any update to this? I’m trying to write a function that takes a wildcard UStruct so I can serialize any struct to JSON (including Blueprint structs) without having to write specialized code for each one of them, however It doesn’t seem to be possible to get functions to accept the UProperty or UStructProperty as parameters.
The problem with using CustomThunk and creating a UK2Node_CallFunction is that I couldn’t find any documentation on how it works and the sheer amount of boilerplate code required for a custom blueprint node is frightening. I consider myself fast at learning other people’s code but the nodes have so many virtual functions and the source for nodes that use wildcard variables all have several hundreds of lines I would probably have to drop everything else I’m doing for a week or so to grasp enough of this.
It is possible, I’ve done it few months ago.
I have implemented “Optional” and “Variant” types in Blueprints using wildcards and custom thunk code.
Very useful when I need nullable ints or when I was storing a float and now I need ro store a vector; instead of creating both a float and a vector property, I use the same variable to save either one of the values in Actor Blueprint.
I know this post is multiple years old at this point, but I’ve been looking for exactly this (Blueprint exposed “Variant” type) forever. Would it be possible for you to share this code if you still have it or remember how you wrote it (assuming you even see this after all this time)?