So, I’ve been programming for a long time and I’m trying out Unity for the first time. I’m still trying to wrap my head around the paradigm of Scenes. Basically, where do I create a new scene? For instance, I have an RPG game and i need an inventory screen. I’m very confident I can create the programming structures, but when I have them click on “Inventory” and it brings up the new character inventory so they can move things around, equip, etc., is this a new “Scene” or is this a new GUI on the existing scene? Same things if they enter a shop and need to buy/sell things. When I bring up the buy/sell screne which is going to be full screen and replace the existing page, is this a new Scene or a new GUI on the existing scene?
Also, if its a new Scene, the Scenes seem to be designed to be stateless and atomic. How do I pass the Player object between Scenes so that what they buy in the shop is then part of the Player object in all the other scenes?
I would wager a lot of experienced Unity devs don’t really use Scenes for a lot. This is mostly based on my assumptions, mind you, and I could be entirely wrong.
To me, it seems like Scenes are intended for things like levels where you want to set up a bunch of stuff ahead of time and have a very clear “I am either here or not” kind of situation during gameplay. Personally, I only use a single scene and manage loading of content through prefabs and managers. It’s only a mild nightmare to set up, and testing and debugging is more work than I’d like, but this probably has a lot to do with my inability to plan and create a good debug/test menu system, too.
I use scenes more than that — not for every level, mind you (I prefer to define levels as data files in my own format), but for things like the main menu. In Chesster, we had the following scenes:
Main Menu
Options
Treasures (sort of an Achievements screen)
Main (where the actual gameplay takes place)
…and this is fairly typical in my projects. If I have things that need to be in multiple scenes (such as options accessible also during gameplay), I just make a prefab of those. Nowadays I guess I could also use SceneManager’s additive loading, but I haven’t tried that yet.
Unity is super flexible, to the point where there are essentially an infinite number of ways of doing things. A lot of the time the technique you end up choosing is more of a personal style issue than anything, though sometimes there can be performance trade-offs.
Personally I wouldn’t do UI screens as scenes. I would do my entire UI as a GameObject hierarchy containing children that represent “screens” (those GameObjects could be activated or de-activated to show your various screens/sheets) and save the whole thing as a prefab. At that point, you’d use Unity’s scene editor to edit the prefab, but not load it from a specific scene during the game.
So you could have a starting “master” scene that contained your UI prefab and other stuff you want to have around for the entire game.
If you did want to load other scenes, you can call DontDestroyOnLoad() in any components attached to GameObject’s that you want to survive a scene load:
It’s also worth pointing out that everything doesn’t have to be a GameObject (and doesn’t have to be in a scene). You can create singleton managers (or I suppose just use static methods for whatever) which will be persistent.
There are a million ways of doing everything, for better or worse.
This used to be an easy question. A scene was everything that would be expected to be in the game at one time. Whenever you expected a loading screen, that was changing scenes. So my projects would typically look like this:
Splash screen
Main menu
Level 1
Level 2
Level 3
…
Now with additive loading and multi editing of scenes, a scene can be much less. A scene is now a self contained game entity (ie a scene should hold references only to assets and not to other scenes). That means you can build a scene for just your UI. You can build a scene just for your player character. And so on.