¿How to prevent frame drops when you do big calculations?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nitsuga

Hi!
I have a function that does a lot of loops and calculations, this causes the game to hang for a moment and the pfs to go down. So I’m looking for a way to be able to do those calculations in a greater amount of time but without the game getting stuck or missing frames. I could use yields but it doesn’t seem to be very efficient.

:bust_in_silhouette: Reply From: whiteshampoo

If you dont need the calculated data immediately, you can use multithreading.
Just start a new thread and check in every frame if it has finished (or use a signal). Then you can use the results.

It worked for me, thanks!

Nitsuga | 2021-01-28 08:03