Can I split template definition in UE4?

I created a class named NoName which has a template member function DoSomething().

#include "CoreMinimal.h"
#include "Actor.h"
#include "NoName.generated.h"

class NoName : public AActor
{
	GENERATED_BODY()

public:
template<typename T>
void DoSomething(T input)
{
	//
}
}

But I wanted to split its definition, so I do this trick.

////// NoName.h
#include "CoreMinimal.h"
#include "Actor.h"
#include "NoName.generated.h"

class NoName : public AActor
{
	GENERATED_BODY()

public:
template<typename T>
void DoSomething(T input);
}

#include "NoName_TemplateDefinition.hpp"


////// NoName_TemplateDefinition.hpp
#include "NoName.h"

template<typename T>
void NoName::DoSomething(T input)
{
//
}

And I got this error
#include found after .generated.h file - the .generated.h file should always be the last #include in a header

Is there any other way or suggestion?

Well error tells you all, you placing #include "NoName_TemplateDefinition.hpp" making #include "NoName.generated.h" not “last #include in a header” as error say.

UE4 code expect you to follow it’s convention, and by them you should define in cpp file. UBT compiles all cpp files it finds in module, so you can have multiple cpp files for single class, so don’t include and rename NoName_TemplateDefinition.hpp to NoName_TemplateDefinition.cpp and it should just work

Templates are not supported by reflection system so remember to not place UFUNCTION on template functions and they can be only used in C++

Thanks for the answer! But template implementation should be in header, no? You’ll get a link error otherwise.

I found another solution for this.
By adding #include “NoName_TemplateDefinition.hpp” to where the template function is used,
it seems to be working.

// some other .cpp
#include "NoName.h"
#include "NoName_TemplateDefinition.hpp" // or .cpp :3

NoName->DoSomething<int32>(10);

Will this way make UBT confusing?