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

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



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

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:

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

:slight_smile:

Rama

2 Likes

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