Greetings everyone,
I have a problem when building my game, I have a scene that stores my settings for the player that stays loaded so the player can be upgraded in the menu and have those upgrades go through to the player, but when I build the game, that scene isn’t loaded, I have checked the scene in the build settings, I have put a cube in that scene positioned in the middle of the screen, it isn’t showing up in the build. Everything is perfectly fine in the editor, what am I doing wrong?
I still cannot find an answer. I would really apprecceate some help. Is this a bug? Is it intentional? How can I fix it?
There can many differences between the editor and builds and various things can go wrong. If something breaks in the build, you need to debug to find the difference and then fix or work around it.
Did you check the player log to see if there are any exceptions that could have prevented some code from being executed?
Then add logging or connect a debugger to make sure the code loading your scene is called properly. Also make sure there isn’t anything immediately unloading the scene after it was loaded.
yes. It just tells me the build was successful with the time it took
The idea is it’s loaded on awake, I have added a LoadSceneAsync() on my main script, and checked every script that I wrote to see if it’s being unloaded, which it isn’t. I’m not sure how I can use a debugger as the problem is only in the build, and not the editor.
FIXED IT
Turns out unity won’t load a scene if the LoadSceneAsync() is in the void Start().
This is the script
float loadScene = 0;
void Update()
{
if(loadScene == 0)
{
SceneManager.LoadSceneAsync("PutSceneNameHere", LoadSceneMode.Additive);
loadScene +=1;
}
}
it has to have the LoadSceneMode.Additive or it will unload the current scene. Without the if statement, it will create a new version of the scene every frame.
for some reason, unity didn’t automatically load the scene in the build, so this is how I did it manually.
Thanks for all the help ![]()
That’s the editor log, which shows you stuff about the build. But when you then run the build, its output is logged into the player log, check “Player-related log locations” here for where to find it. It’s important to check the player log whenever something in the build goes wrong.
There’s some weirdness with loading too early during startup but I never had it not load the scene, just async not really being async. Maybe the player log would have contained an error message.
You can also make Start a coroutine/async method and wait a frame, which avoids having to add a field and allows you to wait for the scene to have loaded:
IEnumerator Start()
{
yield return null;
yield return SceneManager.LoadSceneAsync("PutSceneNameHere", LoadSceneMode.Additive);
Debug.Log($"Scene loaded!");
}