How do I set the maximum timer length on per object basis?

I have this line of code:

GetWorld()->GetTimerManager().SetTimer(newEffect->EffectTimerDel, newEffect->PeriodLenght, true);

And it seems to works mostly ok.

But I’m curious how I could set maximum length (or amount of periods ?), which timer can execute, for specific binded object.

You could simply have this timer call a little helper method where you decrement a counter and also do your ‘things’ that it currently does.

int32 counter = 5;

GetWorld()->GetTimerManager().SetTimer(this, &YourClass::HelperMethod, newEffectPeriodLength, true);


// then have this helper method in the class
void YourClass::HelperMethod(){

    // do the things

    counter--;

    if(counter <= 0){
        GetWorld()->GetTimerManager().ClearTimer(this, &YourClass::HelperMethod);
    }

}

I couldn’t find any UE4 internal solution… I’m not sure if this fits in with your current implementation as there is very little information about your project usage to go by. This would accomplish what you need though.

Edit:

I see the “per object basis” and I’m having second thoughts. I guess you could have the counter as a variable of the object initialized to the number of ‘periods’ to call the method, then clear the timer.