Hello,
I’d like to write a simple function for SetTimer with fewer arguments, but I’m having a bit of trouble.
MyAbstractClass.h:
////////////////////////// INCLUDES ////////////////////////
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "Engine.h"
//////////////////////// FUNCTIONS ///////////////////////
FTimerHandle IMyStructures::SetTimer(float DelayInterval, bool bLooping, typename FTimerDelegate::TMethodPtr<UserClass> InTimerMethod) const
MyAbstractClass.cpp:
/////////////////////// INCLUDES //////////////////////////
#include "MyAbstractClass.h"
/////////////////////// FUNCTIONS ///////////////////////
template<class UserClass>
FTimerHandle IMyStructures::SetTimer(float DelayInterval, bool bLooping, typename FTimerDelegate::TMethodPtr<UserClass> InTimerMethod) const
{
FTimerHandle TimerHandle = FTimerHandle();
if (GetWorld())
{
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, InTimerMethod, DelayInterval, bLooping);
}
return TimerHandle;
}
Which, by all accounts should work in theory. But in practice, every time I try to call this new abbreviated function in derived classes like AMyActor.cpp or AMyCharacter.cpp, I get this compiler error:
no instance of function template "AMyActor::SetTimer" matches the argument list. Argument types are: (float, bool, void (AMyActor::*)())
And I’ll get this ugly error unless I declare and define the calling function with a template.
But interestingly enough, if I use the Timer Manager’s SetTimer method:
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, InTimerMethod, DelayInterval, bLooping);
It compiles without issue, and I don’t need to specify a template as part of the calling function’s signature or definition. Why is the compiler complaining with MY class’s method, but not with the Timer Manager’s method?
Thanks for your time.