Is it possible to rearrange the Scene Order (the build index) through code?

Hello guys! I am stuck as a duck on this one and have been for weeks.

I’m trying to make it so that once a condition is met, let’s say int i = 5, the scene will be removed from the build order so that the user will never see it again. Or if I could change it’s order in the build index to that of an odd number, and make it so my scene loaders only ever load even numbers in the build index.

HOWEVER, I have not been able to figure out how to reference scenes in the code. Or manipulate their build index - the only way that I know how to do so is through dragging them around with the mouse in Build Settings.

I think its too late to help you, but for others that may get here:
You’ll need your own manager script to do this. It can call SceneManager.sceneCount to get number of scenes in the build. There’s no way to remove any directly, But you can keep track of loaded ones and consider these conditions. For example (using each scene just once):

List<int> unusedScenes = new List<int>();
Awake()
    {
        for (int i = 0; i < SceneManager.sceneCount; i++) unusedScenes.Add(i);
    }
Load()
    {
        if (unusedScenes.count == 0) { Debug.LogError("No more scenes!"); return; }
        int i = (int)(Random.value() * unusedScenes.count);
        SceneManager.LoadAt(i);
        unusedScenes.remove(i);  
    }