Set timer by function name - pass parameter to function?

I asked about this last week

Basically I spawn a timer for each task request from client and I would like to execute the function with different parameters sent by each client.

I tried Shohei’s suggestion and it seems to work at first but now that I tested more scenario I found that it doesn’t work.
When more than one task were passed to the server concurrently, only the last set of parameters sent by the last client were being used when both timer event triggered.

Any idea how to solve this problem?

What are the parameters you are passing In and where are you getting these values from?

The parameters are passed in when client call a Custom Event that Executes On Server.

Look at this blueprint


Function QueueTask is being called in a Executes On Server Custom Event. So let’s say now we have two players trigger this server event with different parameters

PlayerId 1 with his own Param1, Param2 and TriggerTime.

PlayerId 2 with his own Param1, Param2 and TriggerTime.

When function DoTask is triggered by the timer it needs to process according to above parameters.

Yes I get that but I’m saying what are the parameters you’re are passing In just ints? And what is it you want to do with these passed in values when the timer operates ?

The params are like ItemId, Location and etc. The actual usage is something like player1 send in a request to build item1 which needs 5 seconds to complete, player2 send in a request to build item2 which needs 7.5 seconds and so on. Each request will spawn a timer and server execute their task when each timer trigger.

Ok I think I understand now can you show me the blueprint for que task event

Ok here’s how the blueprint like

client 1 and client 2 blueprint only serve to illustrate multiple client could request

Any solution for this or any alternative way to achieve this…?

Now I have changed to spawn only 1 timer in gamemode that runs every 100ms to check and perform queue tasks. Not sure if it’s the best way but at least it work.

Old topic, but since I’m new to Unreal Development and I’ve also come across this issue on 4.24 I thought it might be worth sharing my work around.

I had the exact same problem. Except that I had an Event where I would have a Set Timer by Event delegate. Tried to move it to a function and it was also no good.

What I did was create an Object blueprint that is used to set the timer and then dispatch an event upon time out. Instead of having the event set the timer in the main blueprint, it Constructs the Object then Binds an Event to the Event Dispatcher that, then, handles the task.

Something like this…

Task manager blueprint:

Scheduler object:

Don’t know how efficient this setup is in terms of system resources consumption, but it solved my problem. From what I understand, given the scheduler Object references are properly cleared, it should be garbage collected and destroyed.

Didn’t try Shohei’s approach mentioned in the original post.

What I could reason of the blueprint behavior is that the Set Timer delegate node will always get the last parameter sent to the event/function that sets it up, what actually makes a lot of sense, thus if it’s called twice in a time interval shorter than the time out it will mess things up.

Hope it helps anyone with the same issue.

1 Like