So I’ve got a routine that instantiates ~40,000 gameobjects, mostly sprites. It takes about half a second to run on my development machine, pushing a single frame out over the duration. I’d like to use a coroutine to spread this process out over the appropriate number of frames. I can’t use a separate thread because it’s all unity engine operations.
However, Yield doesn’t really do what I want it to do. It yields, at minimum, to the next frame. Taking 40,000 frames to load the level would obviously push the load time to unacceptable lengths. Any place I care to put the yield statements - every 10,000, every 1000, whatever - could be tuned to a single environment, but would either lower the framerate or increase the load time anywhere slower or faster.
The other solution I was thinking of was to use a C# Stopwatch to Yield after a given amount of clock time, but again, it’s a bit of a guessing game to set that delay, and in my experience Stopwatches can be processor expensive themselves somehow.
Thank you for your attention.