In my game, when I load another scene, I generate a map from tile at the same time, so unity freezes for some seconds. And I want a loading scene with an animation. But the animation also stops. Is there any ways for continuing the animation when the freez happens?
Not if the main thread is frozen. Can you pull the map generation into a job so it runs on a separate thread or change the code so it utilizes coroutines or async/await to keep the thread moving?
Thanks for the reply, sorry for being late! I don’t actually know how to do all the ting you said in your reply. Im not so familiar with unity and programming overall. Do you have a tutorial for it?
I remembering thinking this series is a decent introduction: https://www.youtube.com/watch?v=kREqrc8lvwI
It might not be the solution if you’re not a programmer or are just starting. Are you using a third party asset for the map generation?
The corouting solution would be dependent on how your map is created but it might look something like this:
void Start() {
StartCoroutine(CreateMap());
}
private IEnumerator CreateMap() {
for (var i = 0; i < mapSize; i+=batchSize)
{
// generate batchSize amount of tiles
for (var j = 0; j < batchSize; j++) {
CreateTile(j);
}
// wait until next frame to generate some more tiles
yield return null;
}
}