How can I set up a timer with a payload/parameter?

Hi there,
I haven’t used Timers before but I’m trying to set one up that carries an int as a payload/parameter in my UObject child class.

The goal is to be able to detect if an input has been held down for at a given amount of time (delay) or more.

The method using the timer (called every frame):

bool UMagic::testInputInitTime(int spellIndex, bool input)
	float delay = 0.1;
	FTimerDelegate del;
	del.BindUObject(this, &UMagic::finishDelayTimer, spellIndex);
	UWorld* const world = GEngine->GetWorldFromContextObject(this);
	FTimerManager timerManager = world->GetTimerManager();
	if (input)
		// Input is held
		if (!timerManager.IsTimerActive(del))
			// If delay timer is not set, set it
			timerManager.SetTimer(del, delay, false);
		passedDelay[spellIndex] = false;
	return passedDelay[spellIndex];

And the method at the other end of the timer:

void UMagic::finishDelayTimer(int spellIndex)
	passedDelay[spellIndex] = true;

The above code fails to compile with:

1>c:\program files\unreal engine\4.1\engine\source\runtime\engine\public\TimerManager.h(434): error C2248: 'FNoncopyable::FNoncopyable' : cannot access private member declared in class 'FNoncopyable'
1>          C:\Program Files\Unreal Engine\4.1\Engine\Source\Runtime\Core\Public\Templates\UnrealTemplate.h(264) : see declaration of 'FNoncopyable::FNoncopyable'
1>          C:\Program Files\Unreal Engine\4.1\Engine\Source\Runtime\Core\Public\Templates\UnrealTemplate.h(257) : see declaration of 'FNoncopyable'
1>          This diagnostic occurred in the compiler generated function 'FTimerManager::FTimerManager(const FTimerManager &)

Could anybody point out what I’m doing wrong, or maybe suggest a better way of doing this?

Thanks :slight_smile:

I’m not familiar with the rest of your implementation but a different way to do this that is similar to your current implementation would be to use a TArray startTimes and store the start time of the action/event you are timing. Then in your function, simply compare the amount of time passed since you did whatever you did to set the startTime[spellIndex]… like this (GetWorld()->TimeSeconds - startTimes[spellIndex]) > YourDelayAmount .


// do on the start of the action/event you wish to time
void UMagic::SetStartTime(int spellIndex){
    startTime[spellIndex] = GetWorld()->TimeSeconds;

bool UMagic::testInputInitTime(int spellIndex, bool input){
    if(!input) return false;    
    float YourDelayAmount = 1.0f;
    // return true if past delay time, false if not!
    return (GetWorld()->TimeSeconds - startTimes[spellIndex]) > YourDelayAmount;