[Request] Blueprints: Support for Template Types

Dear Friends at Epic,

I was trying to design an arbitrary cast node, I got this to compile

/** Cast anything to anything! IsValid will let you know if the cast was successful or not */
	template 
	UFUNCTION(BlueprintCallable, Category = "VictoryBPLibrary")
	static FORCEINLINE PtrType* Cast__VictoryCast(UObject* ToBeCasted, PtrType, bool& IsValid )
	{
		IsValid = false;
		PtrType* Casted = Cast(ToBeCasted);
		if(Casted) IsValid = true;
		return Casted;
	}

But this particular node is not recognized when I am in the editor

Do Blueprints have support for template types?

could this feature be added?

thanks!

Rama

I’m surprised that compiled and will make a note to look at why. The UFunction created from that is probably not well defined or what you expect it to be and in general, using the C++ syntax for templating UFunctions isn’t really a viable approach.

For blueprint nodes, we do have the ability to do template-like (referred to as wildcard) pins as you’ve seen in the array functions, however, at the moment it requires a fair amount of custom behavior on the node to support the typing of the wildcard and the implementation of the functions backing it are also quite specialized. I believe it is somewhere on the (lengthy) wishlist to be able to make wildcards a little more generically usable, but it is low priority relative to other potential features and improvements.

For the specific thing you’re showing here I’m not all that clear as to why you’d need this cast as opposed to using the Cast functions that we generate for all BlueprintTypes.

Thanks for the detailed answer Marc!

“For the specific thing you’re showing here I’m not all that clear as to why you’d need this cast as opposed to using the Cast functions that we generate for all BlueprintTypes.”

I was mostly just goofing around trying to see if I could get c++ template types working.

Thanks for your wildcard explanation!

:slight_smile:

Rama

Hi all,

The reason it compiles is due to the fact that UnrealHeaderTool ignores almost everything unless it encounters a USOMETHING(), so it’s not a template as far as the tool is concerned, it’s just a regular function.

I’m somewhat amazed/scared that the generated code compiled though. :slight_smile:

Steve

Hahahaha

Nice to hear from you Steve!

well I am glad something has come of my tests that interests you :slight_smile:

Have fun today!

Rama