Game state management & and passing data between scenes
I'm not entirely sure if I'm doing this right, but I always considered the scene system in Unity as some sort of state management (rather than e.g. a level system) which allows to group the contents (entities, components) into the usual main states of the game (menu, ingame), which can then be invoked or replaced together.
Now I have a very specific concern and I have no clue how to deal with that in Unity, mostly because of it's abstractions from code and other restrictions:
My game features a procedurally generate terrain where as I'd like to tweak the generator before actually launching it. The tweaking is done in some sort of 'pre-game' state (as part of the main menu) where the values are stored in e.g. TerrainData model class. Usually in other engines, I'd to it like this:
Providing an UI within the menu state to tweak the parameters of the game
Storing the parameters in a view model (and data model)
Instantiate the ingame state (which requires said data model in the .ctor
Pass the data model to a generator and start the generation
Now, here are the main problems:
Most types in unity (scenes, monobehaviors) do not allow constructors because they use it for themselves
It doesn't seem possible to instantiate scenes manually (there's only e.g. Application.LoadLevel("") which only takes the name of the scene, not a instance reference etc.
it doesn't seem possible to pass data between scenes, without reverting to awkward workarounds such as singletons, playerprefs, DontDestroy etc. which are all not really suitable for this case.
So, how can I properly solve this? Is there a better way to manage states rather than scenes? Prefabs maybe?
Backlink to gamedev/StackExchange question: https://gamedev.stackexchange.com/questions/117557/game-states-passing-data-between-scenes
Your answer
Follow this Question
Related Questions
Managing particle systems depending on scene whilst remembering state 1 Answer
[SOLVED] How to load next level? 0 Answers
Cannot interact with new scene 0 Answers
Event when the scene is loaded 1 Answer