unity, LoadSceneMode.Additive mode not working in window build - unity3d

I want to show TWO Scene simultaneously in my application.
EDITOR has not any problem. working good. but if I build for window
application show just one scene, how to fix it?

When you build the project, by default, only the first scene on your build order will be loaded as the first displayed scene. If you want to load multiple scene simultaneously, you should load the extra scenes additively on a script, for example in C#:
SceneManager.LoadScene("OtherSceneName", LoadSceneMode.Additive);
However in the editor, as you noticed, you could add two scenes and both loaded and runs normally when you hit "Play". This is just one of the editor's helpful functionality for editing multiple scene. Notice that on project hierarchy, only a single scene is recognized as the "Active scene". The editor behaves as if you loaded the active scene in "Single" mode first, then loaded the others in "Additive" mode.
Ref: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

Related

Unity 2020.1.0b12.3931 - Objects from scene 2 are visible in scene 1

I don't know if this is some sort of bug or (which is likely) I'm doing something wrong, but I have two scenes.
menuScene is a starting point and it suppose to have nothing but canvas with some input fields, sliders, labels and a button.
Clicking the button moves to gameScene, which (by default) contains some objects.
This is what I see when I run the project:
What do I need to do to make only menuScene visible on launch?
In general: Unity 2020.1.0b12 is a BETA version and not unlikely to have a lot of bugs. If you are not investigating the most newest features but rather want to implement a serious project you should stick to the latest stable Unity Version (currently 2019.4 LTS).
You have opened both your Scenes in the Editor! In your Hierarchy I can see both scenes menuScene and gameScene.
In this case SceneManager.Load loads your already existing but currently unloaded (disabled) scene (basically only enables it) but keeps the other scene(s) in place.
Note that within the Editor Multi Scene Editing is possible and even if you then start the PlayMode both scenes are still there.
However, in a build later only the top-most scene of the list in the Build Settings is loaded in single mode!
The follow up error you got is due to your scenes not added to the Build Settings. Simply drag & drop your two scenes into the list in the Build Settings.
Then open only the first scene in the Editor (click Remove on the other ones) and then enter PlayMode again. Now it should load your scenes in single mode

how to switch between loaded scenes

I am new to unity and working on a projects.
I want to work with multiple scenes.
some of my scenes are like option menu in the game.
from my main screen I want to open an options scene and when I am done I want to move back to my main scene and when I am back I want to keep the things done in main scene before the options scene opens
I can change scenes with SceneManager but it loads the screen as new as if I did nothing there
is it possible to switch between loaded scenes without loading again? I think that if it is; I can continue from the progress in the main scene
if it is not how can I continue my progress (do I have to keep all the data and when the scene starts load back from that data? )
The SceneManager class provides lots of useful ways to manage your scenes. You can find documentation here.
Using multiple scenes to separate your logic is a great approach, and using the LoadSceneMode.Additive option when loading a new scene lets you load one scene alongside another.
To achieve what you want, you'd roughly need to do the following:
Load your main menu scene.
Load your options scene additively with a call like SceneManager.LoadScene("path/to/options/scene.unity", LoadSceneMode.additive).
Pass input control to your other scene.
Unload the options scene when you are finished with it.
The main menu scene will have been loaded for the entire time, and you won't have to "remember" any values or use DontDestroyOnLoad.
An alternative option is to house all of your menu functionality in a single scene, and switch between multiple canvases. You can find information about that here.
you can create a class with values that you want to keep and put it on a gameobject
and use DontDestroyOnLoad(this.gameObject); so the object won't be removed when you load a new scene

Scene content is shown in game player but not shown in windows build

The scene content is shown in game player but not shown in windows build.
Could anyone suggest what can cause to this kind of problem, Or suggest ways to troubleshoot it?
Please note that :
The scene is properly defined in the build settings
I am using windows 10
I am building for windows
The scene contains some sprites with physics , an imported character with animations (I imported it from the asset store) , a UI canvas with a button, and some scripts that attached to the objects.
The scripts do almost nothing.
The game content is properly shown inside the game player (Unity's Editor player) the problem is only with the build.
When running the build output , Unity's splash screen is shown and then the scene is loaded but its content isn't shown.
I changed the camera background color , and the color is indeed changed in the build , it's just the scene content that isn't shown.
I added a UI canvas with a button , the button is shown.
I am using Unity 5.5.1f1
it is a 2d project
Make sure you are adding the scene to Scenes in Build screen.
Go to File->Build Settings and in the dialog make sure your scene has a check mark on the left.
When running in Editor Unity runs whatever scene you are working on, but when building a player you need to include the scene in the list.
Problem solved.
I deleted the camera and created a new one. It solved the problem.

Share same Navmesh with Duplicated Scenes

I had a Scene with a map (some buildings and roads) and Baked Navmesh, then I started Duplicating the Same Scene with modifying some objects inside (not the map or the world), so all the Scenes were sharing the same Navmesh somehow, then I deleted the Navmesh accidentally, Now the only way I seem to find is to create a new baked Navmesh for every Scene which will increase the build size too much!, How can I re-share the same baked Navmesh with all Scenes since all have the same map inside ? I am using Latest Unity3D.
Before You Start: if you have a lot of assets in your project changing serialization to Force Text may take a lot of time. So you may want to copy the target scenes to a new project, do the below mentioned steps and paste them back. :)
There is no way to do this from Unity editor, but there is a workaround:
Go to Edit > Project Settings > Editor and change the Asset Serialization to Force Text (default is Mixed) - this makes sure all assets, including your unity scene files are saved as text documents
Now open your scene file (the one with baked NavMesh) in any text editor
CMD+F or CTRL+F to focus on search bar and type "NavMeshSettings". In NavMeshSettings the last entree should be m_NavMeshData:{fileID:1234 //and some more stuff here} - this is reference to your baked NavMesh asset file. Copy the whole line
Now open the second scene that you want to share your NavMesh to (open in text editor again). Find exactly the same line starting with m_NavMeshData, delete it and past the line from the previous scene.
BOOM!
Edit/Tip: You may want to change serialization to Mixed again if you want to. The only downside of texted serialization is bigger files. It is mostly used for version controlling and merging and the scenes and stuff...

Add scene when build Unity project

When I build Unity project I saw that if I add current scene Unity or not the game still run fine.
So what is the purpose of add scene ?
If you have not added any scenes then unity will build with your current opened scene by default. The purpose of adding scene is to handle among multiple scenes like Main Menu, Store, Gameplay, Gameover etc. To get more than one scene, you have to add all the relevant scenes, otherwise unity will not recognise the scene when you want to switch to another scene.
As long as #Hamza Hasan answer is correct, I think that question author means something diffrent.
He asks why he should add scene if it works fine in Editor without this action.
So the answer is, if this scene is not first default one (and it is your case), you wont be able to load it programaticaly, as it wasnt included into build even if it works in Editor. It works in Editor couse it was loaded into memory opening the scene.