When I click the button, it returns a runtime error and doesn't load next scene

It returns a scene index of four which is one more than the number of scenes even though I only click once. I am not using the latest version of unity, which may or may not mean anything, but go ahead and look at my code. The only thing I can think is that it might somehow recurse through the function, even though load next scene and load scene are different.

image

Hi Daniel,

Can you pop a screenshot up of your Build Settings, displaying the scenes that have been added please.

There’s a deleted scene at the top… this may be where the count is going wrong, would seem odd though.

For a quick win, try saving all your scenes, save the project, close Unity, re-open Unity and then check those Build Settings again, has that deleted scene disappeared now? If so, run your game again and see if the behaviour has changed.

I think that might have been it, that was weird.

1 Like

I suspect the scene which was deleted was the SampleScene that you get when you open a new project. Odd that it should have counted it, but anyway, glad you can move forward :slight_smile:

I guess I had to shut it down and open it again, because it’s in the video as well and it worked just fine…:face_with_monocle:

1 Like

hmmm, weird. I wouldn’t expect Unity to count them, its clearly identified that they have been deleted, unfortunately in both the lectures case, and your own, deleted but not removed from the Build Settings first - hence the greyed out line - looks almost like a heading doesn’t it.

Without being able to see the project as it was with the issue it would be a bit hard to replicate/diagnose further. Another cause of counts being different to that which you expect can often be a case of having your script added multiple times to either the same GameObject or different ones, I don’t think this would have applied to your specific case though which is why I didn’t mention it before - but worth remembering :slight_smile:

Privacy & Terms