Hello Unity Community,
I’m currently making a top down shooter game where the level is generated randomly using a noise map.
For that I created an empty object to the scene and added the script to it so that the level is generated with two nested for-loops.
Now what I want to do is that if you start the level from the main menu the world is first generated and the progress of the generation is shown in the loading screen using a progress bar and after it is done generating the level becomes active.
What I did yet is loading the scene asynchronously using the SceneManager and show the progress, but the script to generate the world is called after the scene becomes active.
I also found out that I can prevent the scene to become active after it’s done loading using the AsyncOperation.allowSceneActivation boolean, but I can’t figure out how I can call the script from the other scene now.
May have anyone an idea?
Thanks in advance
Maybe i’m missing something, but doesnt the scene have to be active in order to run scripts in the first place?
So if you want to show the process of generation (or a progress bar or something), then you could either do that in a designated scene, or simply prevent gameplay from taking place until the map finished generating, if that’s what this is about.
You could just load the level from the main menu and have it start, immediately show a loading screen with progress bar and start generating the level. Once the level has been generated, gracefully remove the loading screen and you’re done. No? I don’t really understand what the problem is.
Or if it’s data that you need time for loading you could make the loading screen a scene by its own where all that is done is generating the level data and show that progress on a loading screen.
Pass the data of the generated level to a singleton class which carries it over to the newly loaded level.
so:
- Menu: add a singleton class which carries over to the loading scene.
- Loading scene: generate the level and pass the data to the singleton class.
- Level scene: create the level from the generated data in the singleton class.
Or you could create a public static GameManager which sits in a Resources folder. This would replace the singleton class and is also accessible from any script in any scene.
Thank you very much for your solutions!
Loading loading the level, showing the loading screen and hiding it when it’s done generating is a good solution, at first it was too slow in a coroutine, but I yield returned it after every X coordinate generation, not after every single block. It’s fast enough for my map size!
And again, thank you for your solutions ![]()