I am currently building a game in VR and some of the actions I have to perform require a bit of intensive computation. The problem is, predictably, when I click on the button launching computation, the engine becomes too busy, and Steam Chaperone takes over while the computation finishes too avoid freezes. (typically, I might have to display 3000 objects and on a clic of a button, a script computes the ideal position of each of them based on some criteria, script that is well optimized, but still computation intensive for high object number)
Is there a way to run the computation in parallel to the game, giving priority to the basic interactions, and display the results gradually as they are available ? (or all at once at the end if that doesn’t make the framerate drop). What I am looking for is some kind of a parallel processing maybe.
Thanks a lot !
PS: I use HTC Vive with Steam VR
PPS: c++ or blueprints are both fine for me
Creating new threads that isn’t connected to the main game thread is what you are looking for. I have no personal experience with it yet and not sure if it is going to solve all your problems, but I can link some resources on the topic:
I currently don’t have much knowledge on the topic. Multi-threading is something I know I have to learn down the line to solve some of our problems, but I haven’t had the time to dive into the deep end just yet.
I think (limited knowledge disclaimer) adding a delay in front of the function will make it asynchronous, but it will not be processed in a separate thread.
Ok so I went ahead and implemented a few test functions. Most of it works.
However, I already have some quite complex blueprints in my project and it would be a pain to recreate all of them inside a c++ class. Any idea if there are some kind of a macro out there that would perform any action multi-threaded from blueprints ? (I found some Vega plugin but it is not supported anymore. )
Also, I have read something about adding a simple delay of 0ms making the current execution asynchronous. This in turn suggests that it might then run on a separate thread. Do you know how this works ?