The best way to load scenes ingame

Hi everyone,
I was just wondering, what is the best way to load scenes like levels. I dont know how unity loads scenes, but im guessing that theres more to it than just going from one scene to another.
At the moment I am using this:


I seem to be running into problems with this, the game crashes between scene loads from time to time, which will ruin my game, and i can’t figure out why. The games not partcuarly big, and when it crashes it freezes my whole computer, and i have to switch the power off, ctrl alt del doesnt even work.
If anyone can give me any ideas that would be a massive help :slight_smile: Thanks alot, Sean

That’s the way to do it. So now you get to debug. I would start by making your ‘next’ scene empty. See if you can switch to that empty scene. If so, start migrating game objects one by one from the scene that was crashing into that empty scene, noting when it starts crashing again. The last thing you added will be the culprit and then you have to find out why.

If trying to swtich to an empty scene still crashes, then it’s something in the ‘destroy’ phase of your current scene. Start by disabling game objects one by one until it stops crashing. The last thing you disabled will be the culprit, then you have to find out why.

Hey Supersheep,

I don’t see anything wrong with your use of “Application.LoadLevel()”.
I use it all the time to load scenes according to their names, but, as Amasiye313 suggested, you can also use the indices.

Maybe you should try setting up a new project with two scenes, each scene having a gameobject inside it that will allow you to go back and forth between the scenes based on input (and nothing more), so that you can have a good comparison between both projects and it’ll tell us whether there is problem with the scenes and project that you have currently (maybe they’re overloaded in some way).

If you make this new project and the scene switching works, then I’d say the culprit lies elsewhere in your project, but I’ll make no guesses until I hear back.

Let us know how it goes, yeah? Good luck!

Possibly fixed it by removing a group of objects that all had ridgidbodies attached i’d used to mke a wall out of individual bricks. The scene it was loading from crashed during the destroy phase i think. Fingers crossed its ok now, but its one of those annoying bugs that pretends to be gone and then comes back for no reason.