Handling A TArray(FTimerHandle) on Finished Timers


I’m making a component that handles tracing data. The user can input Trace-Data to be started. I want it to have 3 models of Tracing: Single, Timed (Running on Timer Trigger by Timers), Timed(Running every Tick by Tick). The setup works well when dealing with a single instance of said information (the variables are stored in an FStruct). At the end of each Tracing’s process, the Saved Tracing and Timer Data are respectively deleted.

From this, I am in the process of making it TArray Compatible. Both the Single and Tick Based ones already work; however, I am somewhat stuck for the Timer One since On-Timer Finalization there’s no direct way to really know which Array Item was the one that finished. I mean this because I wish to make this system as dynamic as possible; this meaning that the user can add as many Array Items as needed and the SetTimer that I use utilizes void(void) functions as outputs (delegates could work but the events wouldn’t fire within said component).

Like the single instance one, upon Timer finishing, I would need to know how to split the data and determine which timer was the one that finished (without adding a limit to the amount of timer-based Items that there can be).

At the moment, I have an FStruct that stores an FTimerHandler and an integer (Which tracks which respective Trace Data Array-Item is used by). I’ve looked at FTimerManager | Unreal Engine Documentation but can’t seem to find what I’m looking for/a way to implement from it.

What do you recommend / suggest?

You can send argument to binded function, by creating custom FTimerDelegate, like this:

FTimerDelegate MyDelegate = FTimerDelegate::CreateUObject( this, &AMyClass::MyFunction, MyArgument, MyOtherArgument ); // you can plug more or less arguments in

Then put that delegate in SetTimer.

Also “delegates could work but the events wouldn’t fire within said component”, the this part that you point function to call is the object that delegate/timer will call saying this means it will call object that set the timer/delegate. So make sure you point to those components in order for timer to call them.

Okay, I think I get the idea. So I include this created object within the declaration of the timer? Do I need to store this Object in a standard variable?

I’m going to tag 's as the appropriate one. For Future Reference:

in the H File:

	void ResponseToTimerDelegate(int IndextoReferTo);

in the CPP File:

        FTimerDelegate MyDelegate = FTimerDelegate::CreateUObject( this, &UComp::ResponseToTimerDelegate, IntegerVariable );
        GetOwner()->GetWorldTimerManager().SetTimer( TimerHandle, MyDelegate, TimerDuration, false );