- Home /
Why in the editor I see the scenes loading fine but in the build it's different ?
This is the only script that run when the game start that loading scenes. And it was working fine before. And it's working fine now in the editor only not in build:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadScenes : MonoBehaviour
{
private Scene scene;
// Use this for initialization
void Start()
{
scene = SceneManager.GetActiveScene();
StartCoroutine(WaitForSceneLoad(SceneManager.GetSceneByName("The Space Station")));
}
private void Update()
{
if (scene.name != "Menu" && GameControl.player.activeSelf)
{
if (Input.GetKeyDown(KeyCode.Escape))
{
SceneManager.LoadScene(0, LoadSceneMode.Additive);
StartCoroutine(WaitForSceneLoad(SceneManager.GetSceneByName("Menu")));
}
}
}
public IEnumerator WaitForSceneLoad(Scene scene)
{
while (!scene.isLoaded)
{
yield return null;
}
if (scene.name == "Menu")
{
SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1));
GameControl.player.SetActive(false);
Cursor.visible = true;
GameControl.splash = false;
}
}
}
I didn't change anything. I'm using unity3d 2017.2.0f3 personal
This screenshot is how it is in the editor when running the game and how it is suppose to be when running the exe file after building !
This is a splashes script it's making a splash screen before the game load before the main menu load:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Assertions.Must;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Splashes : UnityEngine.MonoBehaviour
{
[Header("Splash Screen")]
public bool useSplashScreen = true;
public GameObject splashesContent;
private List<Graphic> splashes = new List<Graphic>();
public float splashStayDiration = 3f;
public float splashCrossFadeTime = 1f;
void Start()
{
useSplashScreen = GameControl.splash;
if (!useSplashScreen || splashesContent.GetComponentsInChildren<Graphic>(true).Length <= 0) return;
//if we use splash screens and we have splash screens
#region Get All Splashes
//if you build on PC Standalone - you can uncomment this
//foreach (var splash in splashesContent.GetComponentsInChildren<Graphic>(true).Where(splash => splash != splashesContent.GetComponent<Graphic>()))
//{
// splashes.Add(splash);
//}
for (var i = 0; i < splashesContent.GetComponentsInChildren<Graphic>(true).Length; i++)
{
var splash = splashesContent.GetComponentsInChildren<Graphic>(true)[i];
if (splash != splashesContent.GetComponent<Graphic>())
{
splashes.Add(splash);
}
}
#endregion
//And starting playing splashes
StartCoroutine(PlayAllSplashes());
}
private IEnumerator PlayAllSplashes()
{
//Enabling Splashes root transform
if (!splashesContent.activeSelf) splashesContent.SetActive(true);
//main loop for playing
foreach (var t in splashes)
{
t.gameObject.SetActive(true);
t.canvasRenderer.SetAlpha(0.0f);
t.CrossFadeAlpha(1, splashCrossFadeTime, false);
yield return new WaitForSeconds(splashStayDiration + splashCrossFadeTime);
t.CrossFadeAlpha(0, splashCrossFadeTime, false);
yield return new WaitForSeconds(splashCrossFadeTime);
t.gameObject.SetActive(false);
}
//Smooth main menu enabling
splashesContent.GetComponent<Graphic>().CrossFadeAlpha(0, 0.5f, false);
yield return new WaitForSeconds(0.5f);
splashesContent.gameObject.SetActive(false);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
StopCoroutine(PlayAllSplashes());
}
}
public void ExitGame()
{
Application.Quit();
}
}
When I build the game in File > Build Settings... I added both scenes 0 is the main menu and 1 is the second scene I have:
Then I'm running the exe built file: And the result is that I see the splash screen but then when it's loading the main menu I don't see the second scene, Second scene is the "The Space Sttion" and the first scene that load is "Menu" some objects since the second scene is the active one so like in the editor I should see the spacestation the skybox.
The main menu in the editor is fine the main menu in the build seems something is wrong. Seems like it's not loading or not making the second scene to be the active one.
I can't figure out why in the editor it's fine but not in the build. The reason I'm loading both scenes when the game starting and why the active scene is "The Space Station" is since I want to see some objects from "The Space Station" scene with the "Menu" scene.
But again in the editor it's working fine I see the main menu and the space station and more objects from the two scenes. In the build I see only only the main menu when running the game it seems like it's not activating not making the "The Space Station" scene to be active or it's not making the "Player" object to be enabled false off.
But I used a break point and it does getting to the lines:
SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1));
GameControl.player.SetActive(false);
I tried to make new clean project but same problem. Working fine in editor but not in build.
What I didn't try ? Everything:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadScenes : MonoBehaviour
{
public GameObject player;
Scene CurrentScene;
// Use this for initialization
void Start()
{
GameControl.player = player;
//SceneManager.SetActiveScene(SceneManager.GetSceneByName("The Space Station"));
//GameControl.player.SetActive(true);
//SceneManager.SetActiveScene(SceneManager.GetSceneByName("The Space Station"));
//SceneManager.LoadScene(1, LoadSceneMode.Additive);
StartCoroutine(WaitForSceneLoad(SceneManager.GetSceneByName("The Space Station")));
}
private void Update()
{
//if (!SceneManager.GetSceneByName("Menu").IsValid())
//{
// Cursor.visible = false;
//}
//CurrentScene = SceneManager.GetActiveScene();
//if (CurrentScene.name == "Menu")
//{
// Scene name = SceneManager.GetSceneByName("The Space Station");
//}
}
public IEnumerator WaitForSceneLoad(Scene scene)
{
while (!scene.isLoaded)
{
yield return null;
}
SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1));
GameControl.player.SetActive(false);
}
/*public GameObject player;
private Scene scene;
// Use this for initialization
void Start()
{
GameControl.player = player;
scene = SceneManager.GetActiveScene();
StartCoroutine(WaitForSceneLoad(SceneManager.GetSceneByName("The Space Station")));
}
private void Update()
{
if (scene.name != "Menu" && GameControl.player.activeSelf)
{
if (Input.GetKeyDown(KeyCode.Escape))
{
SceneManager.LoadScene(0, LoadSceneMode.Additive);
StartCoroutine(WaitForSceneLoad(SceneManager.GetSceneByName("Menu")));
}
}
}
public IEnumerator WaitForSceneLoad(Scene scene)
{
while (!scene.isLoaded)
{
yield return null;
}
if (scene.name == "Menu")
{
GameControl.player.SetActive(false);
SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1));
Cursor.visible = true;
GameControl.splash = false;
}
}*/
}
Each time I tried something I used a break point in the editor and it was getting to the lines. And yet in the build the result is not the same as in the editor.
This is a screenshot showing the result when running the built exe file:
It's not even close to the result in the editor. Can't figure out what is wrong.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Script works in Game View, but not in build 0 Answers
My android app build has more bugs on it than the editor/deveploment version 0 Answers
How do I solve a BuildAssetBundles Compilation Error that only occurs in the Editor? 1 Answer
Error with instantiate after build 1 Answer