Scene Unity

0 views
Skip to first unread message

Author Metcalfe

unread,
Aug 4, 2024, 11:45:33 PM8/4/24
to vilthisigpi
Scenesare where you work with content in Unity. They are assets that contain all or part of a game or application. For example, you might build a simple game in a single scene, while for a more complex game, you might use one scene per level, each with its own environments, characters, obstacles, decorations, and UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info

See in Glossary. You can create any number of scenes in a project.


When you create a new project and open it for the first time, Unity opens a sample scene that contains only a CameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info

See in Glossary and a Light.


To create a new scene from the New Scene dialog, select a template from the templates list, and click Create. For a detailed description of creating a scene this way, see Creating a new scene from the New Scene dialog.


You can also pin a template when you edit its properties. In the scene template InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info

See in Glossary, enable the Pin in New Scene Dialog option.


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?


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.


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:


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.


When you select a scene, Unity will automatically bake all the lights and render things. BUT when you open a scene while playing the game in the editor, Unity will NOT bake the lights,render them, fix the effects and all, and this causes everything to stay dark.


I HAVE FOUND IT! This is a problem with the skybox loading between scenes. To fix it, go to Window>Rendering>Lighting>Environment. There you should see the Source in the Environment Lighting section set to Skybox by default. When I changed this to color(on ALL scenes) it fixed all my problems with lighting. Every project is different, but this worked better than all of the other solutions I have tried.


When the lighting was different from one scene to the next, the first scene was always properly lit, but the second was darkened. When I loaded multiple scenes in a sequence, all the scenes that had the exact same lighting setup were all lit as designed, but any scene that had any deviation from the original was darkened. I got rid of the darkening by just having all the lighting in my scenes be *exactly* the same.


e. If you want to remove the generated lighting for a particular scene, just delete the created folder associated with that scene. If you change the lighting in a scene, just press Generate Lighting for that scene again, and it will overwrite the old lighting data for it.


Guys you can do it with a crutch, make a podo where you copy current scene settings, serialize it as an asset, load another thing and apply those parameters, it can be made with as editor script in an hour.


I have a game with three scenes, two level scenes and a menu scene. When I press play on my level scene the first time, everything works perfectly, but when I go to the menu scene and then later return to the level scene,


the references on the scripts attached to the NetworkManager GameObject were reset. On the scripts shown in the picture below, for example, all but the references that were linked to prefabs in my assets were reset.


Load that scene only once. That's usually called a loading scene. The scene just contains certain manager objects and it immediately switches to the menu scene / whatever... You would never load that first scene again.


If you want to load the scene again and you used DontDestroyOnLoad on one or more object, you have to destroy the objects manually. You can't prevent the objects from being created again since they are part of the scene. Usually al objects get destroyed automatically when you load a new scene, DontDestroyOnLoad prevents that.


I'm making a turn-based battle game in Unity3D and I have 2 scenes (a town scene and a battle scene). Whenever the character meets a monster, the game jumps to the battle scene where the character does battle and go back to the town scene after defeating or losing.


Create two empty game objects (One for Town Scene objects and the other for Battle Scene Objects). You can then either have two versions of your game character(s) or one. Then write a script that simply switches the camera(s) from the town scene to the battle scene when a battle is triggered and back to the town scene when the battle is over.


If you have two versions of each character then you would simply need to write the appropriate character controller scripts and activate/deactivate the game characters according to which one you are using. This is how games like Final Fantasy 7,8,9 achieved the same effect. There were two versions of the game characters: one for battle mode and the other for normal mode.


You could use the Application.LoadLevelAdditive function. This function allows you to load a different scene and rather than destroy everything in the current scene, it takes the new scene and all it's objects and adds them to the current scene.So basically you can use it something like this:


As with the first method you can decide whether you want to have two different versions of your characters or not. One of the pros of having two versions is that if you want to save time by not going into detail with you game models (especially if your game is really big) you can have save processing power by using scaled down models for the town scene and using polished more detailed models for the battle scene, assuming your battle scene is a small stage representing the place where your characters are fighting. Think final fantasy VII. Just something to consider.


I know this is an old post, but there is one more method that can be used. This would be to save the state of the scene. This comes in handy when you don't expect users to have the resources for loading 2 scenes with the Application.LoadLevelAdditive. That method potentially can use twice the resources.


When you save the state (save all information that can change to a file or DB) you can then load the level at a later time and not have it sitting in memory. You could also use this to save your game.


I know it is on old post. But I have found another, very easy solution for my case. Just deactivating all GameObjects from one scene while the other is active and then reactivate it, as soon I go back to the root scene:


In my game there is a map view that contains a 50x50 grid of tiles. When you click on the tile you get sent to that tiles view and attack things, etc. The only difference between these "tiles" as far as the code will be concerned is the tiles ID, aka. which number on the grid. That number will be passed to the server on init to handle the rest.


I could use DontDestroyOnLoad(); when the tile is clicked to preserve the tile ID on scene switch but 1) it only accepts gameobjects not just an int variable 2) I don't need/want to preserve that variable for anything more than the init in tile view. So while it could work it seems like overkill.


You can make a static class that holds the information for you. This class will not be attached to any GameObject and will not be destroyed when changing scene. It is static which means there can only be ONE of it; you can't write StaticClassName scn = new StaticClassName() to create new static classes. You access them straight through StaticClassName.SomeStaticMethod() for example and can be accessed from anywhere. See this example on how to store a value in a variable, change scene and then use it in that scene (please note the added using UnityEngine.SceneManagement;):


You don't need to have the entire class static (if you for some reason need to create more instances of it). If you were to remove the static from the class (not the variable) you can still access the static variable through StaticClass.CrossSceneInformation but you can also do StaticClass sc = new StaticClass();. With this sc you can use the class's non-static members but not the static CrossSceneInformation since there can only be ONE of that (because it's static).


This script uses a key-value approach for storing and modifying variables inside a static class that means it is available across scenes so you can use it as a cross-scene persistent storage, so all you need to do is import the script to your Unity project and use the API (check below for an example):

3a8082e126
Reply all
Reply to author
Forward
0 new messages