I have some confusion with scenes in Unity3d and I was not able to find any resources about them.
Scenes contain the objects of your game. They can be used to create a main menu, individual levels, and anything else. Think of each unique Scene file as a unique level. In each Scene, you will place your environments, obstacles, and decorations, essentially designing and building your game in pieces.
Use Flythrough mode to navigate the Scene View by flying around in first-person, similar to how you would navigate in many games. Click and hold the right mouse button. Move the view around using the mouse, the WASD keys to move left/right/forward/backward, and the Q and E keys to move up and down.
Scenes in Unity can be thought of as unique levels or even separate screens like a main menu. In the previous article, we created a Game Over screen by simply displaying text over the existing Game Scene. However, to restart a game from a game over state, using Unity's Scene Management is necessary.
Scene View NavigationHold the right mouse button to enter Flythrough mode. This turns your mouse and WASD keys (plus Q and E for up and down) into quick first-person view navigation. Select any GameObject and press the F key. This will center the Scene View and pivot point on the selection.
When should scenes be used? For example in a platformer would every level have to be a different scene? Would the main menu be a scene?
There are no general rules about that. In theory you may have just one scene for the whole game. How you organize your scenes is entirely up to you and often depends on the type of game you are creating.
I think that there are at least 3 features to be considered of using scenes:
GameObjects
and Components
inside a scene (if GO A needs a ref to GO B, and they belong to the same scene, the reference can be serialized and you no longer need to find the referenced object at runtime)Can one overlay scenes?
Yes you can using LoadAdditive. Unfortunately, once 2 scenes are both loaded into memory there is no automatic way of distinguish objects belonging to one or the other. So if you load additive a second level environment, it's up to you to keep track of the previous environment and explicitly destroy it if you need to.
How do assets work between scenes? Are they attached to each individual scene and have to be reloaded every time. Can one specify when an asset is no longer needed?
As defaults every GameObject
of a scene will be destroyed once the new scene is loaded (unless you use an additive scene loading). A way to make a GameObject
survive across scenes is to mark it using DontDestroyOnLoad.
If you need to share a particular "configuration" of a GameObject, you can store it as a prefab, and reference it across scenes (but remember that once in a scene it's a prefab instance, so the GO shares with the prefab the initial serialized and not overriden properties, but 2 instances of the same prefab are different objects).
How does one send data between scenes/interface between scenes?
Several ways, depending on what kind of persistent data you want to share.
GameObject
instance let the object survive using DontDestroyOnLoad
.GameObject
you can consider storing a ScriptableObject inside the AssetDatabase and reference it. There are 2 other ways that I don't like, but just to cite them:
This is a broad topic btw, I hope this answer can be a quite decent overview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With