Usually,we have one Main.unity scene and several battle field scene .Main scene contain gameobejcts with logic controller scripts ,and battle field scene only contains mesh or terrain information.Also the battle field scenes have their owns lightingdata,
In runtime we would like to load or unload battle field scene many times.meantime we shouldn’t delete objects in main scene.so SceneLoadMode.Single is not proper load type to load battle field scene. Then only SceneLoadMode.Additive is left to us.While when using SceneLoadMode.Additive directly, the lighting data couldn’t show normally,just black and white picture. the lighting data is not load directly.
There is one way to solve this: SceneManager.MergeScenes
Scene mainScene = SceneManager.GetActiveScene();
Scene battleFieldScene = SceneManager.GetSceneByName(battleFieldSceneName);
SceneManager.MergeScenes(mainScene , battleFieldScene );
Then the new problem comes, you can’t unload the battlefield scene directly.'cause there is only one scene when battle field scene is loaded. so the lighting data is still there.
Also I have a way to solve this:
SceneManager.LoadScene("MainSceneName")
Another problem:
The objects in main scene is loaded repeatedly.
New solution:
Have a record script to save info whether the main scene is first time to load.
public class Common
{
public static bool isMainSceneFirstTimeLoaded = false;
}
Then each root object in Main scene have a script in awake method, like this:
void Awake()
{
if (Common.isMainSceneFirstTimeLoaded ) Destroy(gameObject);
}
It seems no any other problem . But the script is not gracefull at all. Once there are some logic like OnLevelLoaded th main scene, you need fixed it any where. Meantime you should set Common.isMainSceneFirstTimeLoaded = true after mainLogic runned, That’s to say you need to take care of the scripts execude order. SooooooooooooPainful!!!
Now I want to ask that:
1.why lighting data could not be load with LoadSceneMode.Additive?
2.why not giving a choice for developer to select which lightmaping setting or lighting data to use when using LoadSceneMode.Additive?
or any new solution to solve this?
I also check some posts to say that the prolem has been fixed in Unity 5.0,while still not in 2018.4.2.
btw,I packed the scene data into assetbundle as streaming scene bundle.and load scene after finishing load the bunle .I think the bundle is not the keypoint to this.