S
S
stasersmailov2021-07-27 18:16:21
Unity
stasersmailov, 2021-07-27 18:16:21

Why doesn't the scene change after the build?

In the editor, everything works as it should, but in the build, even under Windows, even under Android, the scene does not change, but does not freeze, but continues to play

. The function code that changes the scene

[SerializeField] private Object[] _nextScenes;

private void OnOutOfProjectile()
    {
        PlayerPrefs.SetInt(ScorePref, _scoreView.Score);
        int rand = Random.Range(0, _nextScenes.Length);
        SceneManager.LoadScene(_nextScenes[rand].name);
    }


6100232ddb902582479603.png
6100233642ab2314360596.png
610023420e209893471153.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Glebov, 2021-08-05
@GLeBaTi

Most likely, the scene objects are reset in the build (look at the logs or set Debug.Log(_nextScenes[rand]))
I didn't find how to attach the scene to the script.
Here are other options:
1) Load sequentially as you chose in BuildSettings:

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);

2) Drive scene names into the list:
[SerializeField] private string[] _nextScenes;
SceneManager.LoadScene(_nextScenes[rand]);

3) Use custom PropertyDrawer:
answers.unity3d.com/questions/242794/inspector-fie...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question