So I made a widget blueprint that executes a Python script that calls ChatGPT with a question that a player has written. Python Script takes 3-4 seconds to execute cuz AI takes time to generate an answer. And for these 3-4 seconds hole game freezes. Like it’s the same frame for 3-4 seconds. I was looking for an answer for several hours and didn’t find a solution. How can I solve this problem?
You need to move the REST calls off the main game thread. The way you are doing it you are blocking the entire game while you wait for the response.
I’m not sure if you can move things to other threads in BP. It is definitely doable in C++.
Generally you will want to have a background thread (probably your new custom made one) handle the REST request/response and it can then call events into the Game thread when the results become available.