Scene loading only working in Unity

Hi!

I’m working on a mobile game, which has a level selection. I have a GameManager singleton instance in the first(Main menu) scene, I put it in the DoNotDestroyOnLoad. Have a list of scene objects in it, which I set in the editor. On start, I take the list of scenes, and get the names, creating as many buttons for level selections as many scenes I have in the list. And when I click on the button, just read it’s property, which is the scene’s name, and load it. It’s perfectly working in editor, even in unity remote with phone, but when I build the project, install it on my android phone, There is no level button(so it didn’t find the scenes in the list), and when I somehow manage to add one, it won’t load the scene.
Does anyone have any idea, what’s the problem?

GameManager:

void Awake()
    {
        if (_GameManager != null && _GameManager != this)
        {
            Destroy(this);
        } else
        {
            _GameManager = this;
            DontDestroyOnLoad(this);
        }

        List<string> tempList = new List<string>();
        foreach (Object scene in sceneObjects)
        {
            tempList.Add(scene.name);
        }
        levels = tempList.ToArray();
    }

SceneManager:

void Start()
    {
        for (int i = 0; i < GameManager._GameManager.levels.Length; i++)
        {
            GameObject newStage = Instantiate(stageReference, new Vector3(0, 0, 0), Quaternion.identity, parentReference.transform);
            newStage.GetComponent<Level>().SetLevelNumber(i+1);
            newStage.GetComponent<Level>().SetSceneName(GameManager._GameManager.levels[i]);
        }
    }

LevelObject:

public void HandleClickedOnLevel()
    {
        if (unlocked)
        {
            SceneManager.LoadScene(sceneName);
        }
    }

When you build the project do you include the desired scenes into the build settings scene list?

Yes

I would try to make a build for windows (or whatever OS you are developing on) and see if it works there to verify wether its an Android thing or not.
I have never worked with Android so I’m not much help with their specifics.

Since you describe your singleton setup do you suspect the issue to arise from this?

1 Like

Okay, I’ll try that in a minute.
And yes, maybe after build, my GameManager loose there scene references, I just have no idea how can I debug that. And what’s the fix for that, if it’s that.

Okay, I think I got it. In my singleton, I stored a list of objects, what were the scenes, and in the loop, I got the name of it, which the build didn’t like. I switched so I give strings to the list, and now it seems like working. Thanks for the help!

1 Like