- Home /
Using LateUpdate() to generate levels procedurally
If your game generates levels procedurally (as the player 'hits' triggers), would 'loading' the generated content in the LateUpdate() function help avoid any 'jerkiness' in performance?
This is purely hypothetical at this point, but I imagine instantiating a fairly complex section of a level could cause performance issues. Since, at least as my understanding goes, LateUpdate() runs after Update(), this would mean no Update() actions would be interrupted?
Well, that makes since to me, but I'm not in any position to say for certain. I'd suggest just checking the players position in an Update, then calling a custom function.
This is just my two cents, anyway. Gibson
Answer by Kryptos · Jul 02, 2012 at 07:33 PM
That is not the purpose of LateUpdate
.
Your best shot is to generate the level across several frames. You could do that by separating the generation into successive steps and by using coroutines to distribute it across lots of frames.
For example, let's say that you have a method that can build a block, and a collection of data that contains all that is needed to build those blocks:
IEnumerator BuildBlocks()
{
foreach(BlockData data in myBlockData)
{
DoBuildABlock(data);
yield return null;
}
}
void DoBuildABlock(BlockData data)
{
// procedural generation of a block here
}