# UFUNCTION with template type does not compile

**URL:** <https://forums.unrealengine.com/t/ufunction-with-template-type-does-not-compile/380348>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [December 28, 2016, 1:13pm UTC](https://forums.unrealengine.com/t/ufunction-with-template-type-does-not-compile/380348 "2016-12-28T13:13:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vb4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vb4](https://forums.unrealengine.com/u/vb4)\
**Post date:** [December 28, 2016, 1:13pm UTC](https://forums.unrealengine.com/t/ufunction-with-template-type-does-not-compile/380348/1 "2016-12-28T13:13:50Z")

</div>

I get the error “Unrecognized type ‘template’ - type must be a UCLASS, USTRUCT or UENUM” when I attempt to use a template type on my UFUNCTION.

This is the function:

```
	UFUNCTION(BlueprintCallable, Category = "Bugfix")
	template<typename T>
	static inline T SetArrayElement(TArray<T>& Array, uint32 Index, T ArrayElement);

```

It compiles correctly if I remove the UFUNCTION macro, but I was trying to test if I can circumvent a bug that I get with arrays in blueprint by using C++, so I need to keep that part.

I read something about using the Header Tool to circumvent a similar issue, but I actually do not know how to use it and cannot find any instructions online.

---

<div class="post-metadata">

**Author:** ![Dartanlla](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dartanlla/32/724052_2.png) [@Dartanlla](https://forums.unrealengine.com/u/Dartanlla)\
**Post date:** [December 28, 2016, 6:17pm UTC](https://forums.unrealengine.com/t/ufunction-with-template-type-does-not-compile/380348/2 "2016-12-28T18:17:34Z")

</div>

I did some research and found in the past Epic said that UFUNCTION() does not support the template type.

> **[\[Request\] Blueprints: Support for Template Types](https://forums.unrealengine.com/questions/7102/request-blueprints-support-for-template-types.html)**
>
> 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 =...

Here is a workaround for using wildcard pins. This sounds like circumventing the header tool that you were referring to:

[[Tutorial] How to accept wildcard structs in your UFUNCTIONs - Community Content, Tools and Tutorials - Unreal Engine Forums](https://forums.unrealengine.com/showthread.php?56537-Tutorial-How-to-accept-wildcard-structs-in-your-UFUNCTIONs&p=206131#post206131%29),

Also, it looks like you are able to use the template type without UFUNCTION in C++ (not blueprints):

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...
