Issue Making A Shorter Timer Function

Hello there :slight_smile:

I am trying to make a simpler timer function for my project. More along the lines of what UE3 used to do, and I’m running into a bit of an issue. Where it shows “Manager->SetTimer(…)” in the code below, I get red jagged underlines in VC++ saying that

I’m confused as to why this is occuring? I have the SetTimer function definition I’m attempting to use in FTimerManager commented right above the problem line…

Code:

void MyActor::SetTimer(
								float DelayInterval, bool bLooping,
								typename FTimerDelegate::TUObjectMethodDelegate<UObject*>::FMethodPtr InTimerMethod
							)
{
	FTimerManager* Manager = &GetWorldTimerManager();

	if (Manager)
	{
		FTimerHandle MemberTimerHandle = FTimerHandle();

		//SetTimer(FTimerHandle& InOutHandle, UserClass* InObj, typename FTimerDelegate::TMethodPtr< UserClass > InTimerMethod, float InRate, bool InbLoop = false, float InFirstDelay = -1.f)
		Manager->SetTimer(MemberTimerHandle, this, InTimerMethod, DelayInterval, bLooping, -1.f);
	}
}

I think I have found the solution:

It required modifying both the header AND cpp files.

First, in the corresponding header file, I added “template< class UserClass >” and changed UObject* to UserClass*.

	template< class UserClass >
	void SetTimer(
					float DelayInterval, bool bLooping,
					typename FTimerDelegate::TUObjectMethodDelegate<UserClass*>::FMethodPtr InTimerMethod
		 		 );

Then did the same for the cpp file:

template< class UserClass >
void MyActor::SetTimer(
								float DelayInterval, bool bLooping,
								typename FTimerDelegate::TUObjectMethodDelegate<UserClass*>::FMethodPtr InTimerMethod
							)
{
	FTimerManager* Manager = &GetWorldTimerManager();

	if (Manager)
	{
		FTimerHandle MemberTimerHandle = FTimerHandle();

		//SetTimer(FTimerHandle& InOutHandle, UserClass* InObj, typename FTimerDelegate::TMethodPtr< UserClass > InTimerMethod, float InRate, bool InbLoop = false, float InFirstDelay = -1.f)
		Manager->SetTimer(MemberTimerHandle, this, InTimerMethod, DelayInterval, bLooping, -1.f);
	}
}