How to call a function or custom event with asynchronous node multiple times?


For example. When I hitting the button, The print function will only run once and print"333" because of the delay node. I need to get many json response from different web by calling the function multiple time, and because of the asynchronous node, I can only get the last result. I have no thinking of how to fix it?

what might be happening is the Delay is finishing, and it is using the most recent value of String input.
try doing a print string right after you invoke your Print()

pull out of the In_String on the PrintString() and create an Append() node.

something like
A = "Print Start: ", B = String

then change your PrintString() at the end to take an Append() as well

something like
A = "Print Finish: ", B = String

I would also suggest to change the clear delay on your PrintString() to be like 5.0 seconds.

because given the current configuration you would probably be getting 333 (but 3 different times, and right as the previous one fades out (the default is 1.0 seconds) the next delay has finished resulting in it replacing the previous text and do so in place)

for the implementation that you are prototyping you could maybe take the return of your JSon Async fetch and place them into an Array and work with them from that Array instead of Raw.

If your HTTP module only provides async nodes and you need to run an arbitrary amount of requests not known at compile time, you either need to set up a queue system to run them one by one, or wrap the request into its own class so that each request gets its own execution flow.

The latter is much easier to implement.

For the sake of this example I’m gonna use 5s Delay since I don’t have your HTTP plugin, but let’s assume Delay is your method to make requests, which is an async node with some arbitrary parameters and a result pin.

So let’s say you want to send a request every time an event is triggered, but the event can be triggered faster than the time it takes for the request to process.
Naturally you will be tempted to make something like this :

But you will run into the mentioned issue.

Create a new blueprint child of UObject, and move your request call into that BP, as well as the result handling (much easier that way).
I used ActorComponent actually because Delay is not available in UObject, not sure if you’ll have to do the same.

Passing the Caller parameter to the request ain’t necessary here but I figure that for real usage purposes you might need some context to handle the request result.

Thanks for your reply. I am the green hand and need some time to try the way you provided. I need to send the post request with parameters to the target web and then get the response from it. I think there is only async nodes can do that because it can’t be done in a split second.