I’m working on an endless runner and my world is built using large prefabs (let’s say ‘levels’). They are loaded from storage (too many prefabs to keep in RAM), and instantiated one after the other.
The problem is when my player enter the next level, another level is spawned and there is huge FPS drop when a level is spawned.
What can I do to make this level spawning seemless?
Hello.
I recommend you using a IEnumerator ( a corutine ) so you can instantiate one or two prefabs each frame
void Start ()
{
StartCorutine(SpawnThings());
}
IEnumerator SpawnThings()
{
for(int i = 0; i < something; i++)
{
Instantiate prefab*;*
yield return null;
}
}
This way, inside the “for”, when the yield line is executed, the code waits to the next frame to continue, so each frame does 1 “for” iteration, so each frame instantiates only one prefab
Bye!