Error LNK2019 when using C++ template function

So I get this error when I’m trying to call a static templated function from any other class besides itself

Error WorldUtility.cpp.obj : error LNK2019: unresolved external symbol “public: static class AActor * __cdecl GameObjectHelper::GetSingleActorFromScene(class UWorld * const)” (??$GetSingleActorFromScene@VAActor@@@GameObjectHelper@@SAPEAVAActor@@QEAVUWorld@@@Z) referenced in function “public: static void __cdecl WorldUtility::Initialize(class UWorld *)” (?Initialize@WorldUtility@@SAXPEAVUWorld@@@Z)

This is the function in the .cpp file

#include "TestProject.h"
#include "GameObjectHelper.h"
#include "EngineUtils.h"
#include "Engine\World.h"

template <typename Type>
Type* GameObjectHelper::GetSingleActorFromScene(UWorld* const world)
{
	for (TActorIterator<Type> ActorIter(world); ActorIter; ++ActorIter)
	{
		return *ActorIter;
	}
	return nullptr;
}

this is the function declaration in the .h file

#pragma once
#include "InputPlayerController.h"

class TESTPROJECT_API GameObjectHelper
{
public:
	static AInputPlayerController* GetPlayerController(UWorld* const world);
	
	template <typename Type>
	static Type* GetSingleActorFromScene(UWorld* const world);
};

and this is the code where I call the function from

    #include "TestProject.h"
    #include "WorldUtility.h"
    #include "GameObjectHelper.h"
    
    void WorldUtility::Initialize(UWorld* _world)
    {
    	InputController = GameObjectHelper::GetPlayerController(_world);
    
    	AActor* actor = GameObjectHelper::GetSingleActorFromScene<AActor>(_world);
    	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, actor->GetName());
    }

Ahh I see, I wasn’t aware that template functions work a bit differently than normal functions. Thank you for your answer

You have to define the template function in a header file that gets included in any cpp files that call it. Otherwise the compiler isn’t able to actually generate the function for the linker.