Script executed »in the Background« ?

I am having a Script that runs through all the Vertices of a Mesh and applies Vertex Colors. The Script must be executed frequently (all few Ticks, about 10 or 30) but at every Update (Script Execution) there is a short Lag – as expected.
So, the Problem is that running through all the Vertices and applying the Vertex Colors within one Tick is too much for the Engine and that is why the Frames are skipped.
Now, would there be a Way to execute a Script in with »low Priority« so that it would »work slow« and thus not affect the Framerate? (like: »Darnage, the Job can’t be done in this one Tick, well, then I will finish it in the next few Ticks, just let’s keep it subtle…«)

(Now that I think about it, that would surely be a great Thing for many Cases.)

Yes, this is indeed possible. If you have my BGHelper module, I made a Gradual range class (called CGRange) that allows you to loop through a portion of a list at a time, and pick up where you left off next frame. I think it’s useful, and pretty simple to use.

EDIT: You can find the module in the Resources section. If you’d rather do it yourself, it basically just involves looping through a select portion of a list (say, 10 indices), and incrementing an amount until it reaches a certain threshold. Once this happens, it resets the ‘amount’ variable back to 0, and increases the starting index amount so that next time, it can continue through the next 10, for example, indices. Once there are no more values to loop through, you’re finished (so you should catch this eventuality).

Torakunsama did it himself awhile back - he’ll probably share code if you want.