How do I pass parameters into the function called by Set timer by function name blueprint?
If it’s not possible then is there an alternative way to to implement server task processing logic as below
Receive player A request to start task A which needs to be executed after 5 seconds.
Receive player B request to start task B which needs to be executed after 3 seconds.
Receive player C request to start task A which needs to be executed after 5 seconds.
and so on…
Initially I plan to create a new timer for every player request.
I’m pretty sure the method signature for SetTimer only accepts a void delegate. What you can do is set the timer to call a method which then calls the method that requires parameters. There’s nothing stopping you from calling another method in your event.
The problem is that those parameters are only known where SetTimer is created. I could store the parameters into an array but then in the other method being called by the timer will not know which item in the array should be process.
I thought of storing the timer handle into the array and then in the called function check if it’s called by the same timer handle but then there seems to be no way to know which timer handle is responsible to call the function when the function trigger.
I assume this is what you want to do? This should theoretically work.
The best way to do this is probably to send the data immediately to the server and have the server handle the timing. This way you are sure the data is intact. I mainly work with C++ code and it is extremely easy there, but I am honestly not too familiar with the nuances of blueprints.
- Create method that has output (QueueTask)
- Create server method ServerQueueTask that has inputs and outputs equal to QueueTask output (we are just forwarding data here).
- Create a SetTimer node that points to a parameterless function or event…
- Have that event go into your processing node and wire the outputs of the ServerQueueTask node into the inputs of the processing node.
1 Like
Can you post a screenshot of the relevant part of your blueprint? I might be able to better help you if I properly understand your graph flow.
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.
I change Set timer by function to Set Timer by Event, did a quick test and it seems to be working. Wonder if there will be some kind of racing/concurrency condition overwriting the parameters when more players queue task. It looks like it’ll behave like closure and it won’t???Anyway, I’ll find out later. Thank you!
Ok I find that Set Timer by Event doesn’t work too. When more than one task were passed to the server concurrently, only the last set of parameters were being used when both timer event triggered.
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.
I tried to create a blueprint (actor component) for doing the timer event and pass parameters to it (call Add Component to initiate a new instance, so a new timer there and a copy of references) . Then they won’t be messed up with the coming triggers during its execution.
Hope this can help.
While it may seem impossible to pass params to Set Timer
You can always pass method not from this object, but from a separate object (like actor) which stores the parameters you need as object properties.
1 Like
I started trying to do what JediKnight said, but there is still a major flaw to this. You don’t have the timer with the storage object as an argument in the function either. BUT this got me thinking, and I finally realized the solution. You just need to make a separate actor or object to fire your timer and handle everything. When your timer logic finishes, destroy the actor.