- Home /
Scene not loading in build
OK This is beyond stupid... this was all working just fine... I NEVER CHANGED ANYTHING!! This is just something new that decided to happen out of the blue!! It's set to load scene 2 although that's wrong it should be scene 3, but yet in the editor it does load the correct scene WTF?? right??
I do a standalone build and it does not load the next scene. You can see by my attachment how I have my scenes set up... has anyone had this happen before...?? Like I say I never changed anything this just suddenly decided to start happening!!
![using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LogoMovie : MonoBehaviour {
public MovieTexture movTexture;
public RawImage myLogoMovie;
public AudioClip KittID;
public AudioClip LogoOutFX;
float volume = 0.3f; //Clip Volume Setting
public Text inputFieldPilotName;
private int devSt12; //K.I.T.T. Main Intro Screen Toggle On / Off
//public bool KITTID_On_Off = false; //Toggle for KITT to play ID on or off bool set to true by default.
//Setable by Player Prefs from ConFig Screen
public string mainIntroScrnTime; //Set time for duration of main intro screen to remain before transition to main screen.
//Setable by Player Prefs from ConFig Screen
void Start() {
GetComponent<RawImage>().texture = movTexture as MovieTexture;
movTexture.Play();
movTexture.loop = true;
inputFieldPilotName = GameObject.Find("TextPilotName").GetComponent<Text>();
inputFieldPilotName.text = PlayerPrefs.GetString("PilotName");
devSt12 = PlayerPrefs.GetInt ("toggleKITTintro"); //Determins if Intro will play based on setting in Con Fig Screen.
mainIntroScrnTime = PlayerPrefs.GetString ("loadScreenTime"); //Wait Time As Set By Con Fig Screen.
StartCoroutine(Fade("MainScreen"));
}
IEnumerator Fade(string level02)
{
if (devSt12 == 1) {
yield return new WaitForSeconds (float.Parse(mainIntroScrnTime));
Debug.Log ("I Am Waiting For Player Pref Time");
GetComponent<AudioSource> ().PlayOneShot (KittID);
Debug.Log ("I Will Play KITT Intro Because I am Set to True");
//Load Main After Time
yield return new WaitForSeconds (9.0f);
myLogoMovie.CrossFadeAlpha (0, 1.0f, false);
GetComponent<AudioSource> ().PlayOneShot (LogoOutFX, volume);
yield return new WaitForSeconds (0.9f);
SceneManager.LoadSceneAsync (level02);
} else {
if (mainIntroScrnTime != null && mainIntroScrnTime != "")
{
yield return new WaitForSeconds(float.Parse(mainIntroScrnTime));
Debug.Log("I Am Waiting For Player Pref Time");
myLogoMovie.CrossFadeAlpha(0, 1.0f, false);
GetComponent<AudioSource>().PlayOneShot(LogoOutFX, volume);
yield return new WaitForSeconds(0.9f);
}
else {
yield return new WaitForSeconds(3.0f); // DEFAULT WAIT TIME
}
SceneManager.LoadSceneAsync(level02);
}
}
}][1]
[1]: /storage/temp/105359-screenshot-2017-11-10-133526.png
Hi @zentaiguy I may be wrong about this, but it seems to me that you got confused, because you have named the parameter of the Fade coroutine level02
. Then you start the coroutine in lines 50 and 65 of your code as StartCoroutine(Fade("$$anonymous$$ainScreen"))
. So, in effect, the level02 parameter of the coroutine takes the value of "$$anonymous$$ainScreen", which of course, is Scene 3, per your build settings, but because the parameter name is level02, you might be thinking that it's set to load scene 2, which is not the case! I was very confused too by this. $$anonymous$$aybe it would be a good idea to rename the parameter of the Fade coroutine to something else, like "level03", or even better "mainScreen".
However, I don't understand the second part of your question "I do a standalone build and it does not load the next scene". Which is the next scene? and if that doesn't load, which scene loads? Do you perhaps mean that the "$$anonymous$$ainScreen" doesn't load as expected from lines 50 and 65? Please clarify what you mean. It's not clear what works and what doesn't.
Sorry for the late response @pako Yeah that 2nd part is a little convoluted, I apologize for that. What I was trying to say was even with the code appearing to be wrong it loads the correct scene in the unity editor but not in the stand alone build.... even stranger is that even in the stand alone build this had been working long before, I had not changed it as it had been working but like you say the code is wrong and tries to load the wrong scene 02 when it should be 03.... but stage as it seems this had been working from day one when I started this project 3 years ago.... so I can't figure that out even.... makes no sense ???
@zentaiguy does my response help you understand why this is happening in the editor? Because, in your question you say:
It's set to load scene 2 ...
... but as far as I can see, that statement is wrong! you have actually set to load scene 3!!! as I explain in my reply. So, everything is working as it should! I thought my reply was clear, but it seems that you might need some clarifications. Please tell me what you don't understand in my reply above. To put it more simply, it doesn't matter what you have named the parameter of the Fade coroutine. You have named it level02
:
IEnumerator Fade(string level02)
You could have named it anything, e.g. sceneToLoad
:
IEnumerator Fade(string sceneToLoad)
What matters, is the string value that you use when you start the coroutine "$$anonymous$$ainScreen"
:
//Line 34 of your posted code -- this is the scene you are setting to load
StartCoroutine(Fade("$$anonymous$$ainScreen")); //"$$anonymous$$ainScreen" corresponds to scene 3 in your Build Setting, not scene 2!
EDIT: So, in lines 50 and 65 of your posted code, you are loading scene 3, because level02 = "$$anonymous$$ainScreen"
:
Scene$$anonymous$$anager.LoadSceneAsync(level02);
//is the same as:
Scene$$anonymous$$anager.LoadSceneAsync ("$$anonymous$$ainScreen"); // level02 = "$$anonymous$$ainScreen" = Scene 3 in Build Settings
So, in the editor nothing's wrong, everything works as it should! But what about the standalone build, what scene loads up in the standalone build, and when does it load that?
Answer by KnightRiderGuy · Nov 14, 2017 at 07:48 PM
@pako @pako I have not tested it out side of the editor yet in a build but I think this might by pass it not having any preset values... I think it's kind of a catch 22 going on, the player can't set vales if they can't get in so it needs to bypass on the very first start up.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LogoMovie : MonoBehaviour {
public MovieTexture movTexture;
public RawImage myLogoMovie;
public AudioClip KittID;
public AudioClip LogoOutFX;
float volume = 0.3f; //Clip Volume Setting
public Text inputFieldPilotName;
private int devSt12; //K.I.T.T. Main Intro Screen Toggle On / Off
//public bool KITTID_On_Off = false; //Toggle for KITT to play ID on or off bool set to true by default.
//Setable by Player Prefs from ConFig Screen
public string mainIntroScrnTime; //Set time for duration of main intro screen to remain before transition to main screen.
//Setable by Player Prefs from ConFig Screen
void Start() {
GetComponent<RawImage>().texture = movTexture as MovieTexture;
movTexture.Play();
movTexture.loop = true;
inputFieldPilotName = GameObject.Find("TextPilotName").GetComponent<Text>();
inputFieldPilotName.text = PlayerPrefs.GetString("PilotName");
devSt12 = PlayerPrefs.GetInt ("toggleKITTintro"); //Determins if Intro will play based on setting in Con Fig Screen.
mainIntroScrnTime = PlayerPrefs.GetString ("loadScreenTime"); //Wait Time As Set By Con Fig Screen.
StartCoroutine(Fade("MainScreen"));
}
IEnumerator Fade(string level03)
{
if (devSt12 == 1) {
yield return new WaitForSeconds (float.Parse(mainIntroScrnTime));
Debug.Log ("I Am Waiting For Player Pref Time");
GetComponent<AudioSource> ().PlayOneShot (KittID);
Debug.Log ("I Will Play KITT Intro Because I am Set to True");
//Load Main After Time
yield return new WaitForSeconds (9.0f);
myLogoMovie.CrossFadeAlpha (0, 1.0f, false);
GetComponent<AudioSource> ().PlayOneShot (LogoOutFX, volume);
yield return new WaitForSeconds (0.9f);
SceneManager.LoadSceneAsync (level03);
}
if (devSt12 == 0) {
if (mainIntroScrnTime != null && mainIntroScrnTime != "")
{
yield return new WaitForSeconds(float.Parse(mainIntroScrnTime));
Debug.Log("There Was No Player Pref Time Set");
myLogoMovie.CrossFadeAlpha(0, 1.0f, false);
GetComponent<AudioSource>().PlayOneShot(LogoOutFX, volume);
yield return new WaitForSeconds(3.0f);
SceneManager.LoadSceneAsync(level03);
}
}
else {
Debug.Log ("I Could Find No Values To Work With");
yield return new WaitForSeconds(3.0f); // DEFAULT WAIT TIME
SceneManager.LoadSceneAsync(level03);
}
}
}
@zentaiguy did it work on the standalone build? Also, it might be a good idea to provide some default values, which the player can change as soon as he gets the chance. e.g set some values in Start(), and then it's up to the player to change them.
Your answer
