Hello, All,
I come today with another entry to the glorious saga of “Spawn vs. Coroutine” that can be found by typing exactly that phrase into the search bar; however, I come forward with a problem that is perhaps opposite to those posed in all of the other threads: how do I smooth out my code?
My project has a great deal of interface tiles that need to be initialized at the beginning of the game (at the time of writing, it is about 3,200 tiles). All of these tiles have text marquees on them that needs to be properly sized using TextService
and a number of user-input-focused events hooked up to them–including resizing the text if the container is resized. I’ve done a few iterations of code to get the execution time down to a satisfactory level, but I still fear the impact on the user.
Up until this point, the code supporting the tiles was lightweight enough that I could just iterate through them, but I’m at the point now where Studio aborts execution of the code if it is all on one thread. If I run the initializer for each tile in a coroutine
, I get the fastest results, but there is a huge framerate impact. Spawn
seems to keep Studio/the client on the load screen until the code executes, which seems like a better solution, but I don’t understand spawn
well enough to know if I could run into problems using it.
I’ve also tried running the code from the primary thread with RunService.Heartbeat:Wait()
's thrown in between each tile, and while the framerate of that implementation is the highest of the lot, that un-nuanced, broad-stroked response results in some of the tiles taking nearly a minute to pop in. I do recognize that there is likely a middle ground on this approach, but I need help seeing it.
TL;DR - What is a good way to spread out my code’s execution so that it doesn’t tank the user’s framerate but still executes in a fairly unnoticeable timeframe?