# Is it possible to add a function with template in UE4?

**URL:** <https://forums.unrealengine.com/t/is-it-possible-to-add-a-function-with-template-in-ue4/57694>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 9, 2016, 3:41am UTC](https://forums.unrealengine.com/t/is-it-possible-to-add-a-function-with-template-in-ue4/57694 "2016-03-09T03:41:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawnarc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dawnarc](https://forums.unrealengine.com/u/dawnarc)\
**Post date:** [March 9, 2016, 3:41am UTC](https://forums.unrealengine.com/t/is-it-possible-to-add-a-function-with-template-in-ue4/57694/1 "2016-03-09T03:41:59Z")

</div>

I add a template function in my class, there is error LNK2019 when compile. dose UE4 support custom template function?

```auto

template<class T>
T* AssetsLoader::GetUObject(int32 AssetIndex)
{
	if (AssetIndex < 0 || AssetIndex >= AssetsArray.Num())
	{
		return NULL;
	}
	return (T*)(AssetsArray[AssetIndex]);
}

```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 14, 2016, 4:42am UTC](https://forums.unrealengine.com/t/is-it-possible-to-add-a-function-with-template-in-ue4/57694/2 "2016-03-14T04:42:57Z")

</div>

Your template functions need to be posted in your .h file only, if you want them to work easily

I have a wiki on template functions here:

> **[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...

Here’s a template function that I submitted to the engine which Epic accepted in 4.3:

> **[Two new Math functions for you from me in 4.3, Template Min/Max of Array](https://forums.unrealengine.com/showthread.php?20212-Two-new-Math-functions-for-you-from-me-in-4-3-Template-Min-Max-of-Array&p=98583&viewfull=1#post98583)**
>
> Dear Community, In 4.3 you now have available two C++ functions from me, which I gave to Epic! These are template functions for the min and max of an array of any datatype for which the \< operator is defined! You can use my Min/Max of Array...

🙂

Rama

---

<div class="post-metadata">

**Author:** ![dawnarc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dawnarc](https://forums.unrealengine.com/u/dawnarc)\
**Post date:** [March 16, 2016, 9:13am UTC](https://forums.unrealengine.com/t/is-it-possible-to-add-a-function-with-template-in-ue4/57694/3 "2016-03-16T09:13:04Z")

</div>

> [@Rama;492690](#):
>
> Your template functions need to be posted in your .h file only, if you want them to work easily
> 
> I have a wiki on template functions here:
> 
> [A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums](https://wiki.unrealengine.com/Templates_in_C%2B%2B)
> 
> Here’s a template function that I submitted to the engine which Epic accepted in 4.3:
> 
> [Two new Math functions for you from me in 4.3, Template Min/Max of Array - C++ - Epic Developer Community Forums](https://forums.unrealengine.com/showthread.php?20212-Two-new-Math-functions-for-you-from-me-in-4-3-Template-Min-Max-of-Array&p=98583&viewfull=1#post98583)
> 
> 🙂
> 
> Rama

you are right! thx for your supply. by the way, your website is cool!
