[SOLVED] LevelManager does not contain a definition for LoadNextLevel

I can’t understand the error
LevelManager Script: https://gist.github.com/anonymous/a0304bca33b74b2cdd92dde1a9d5e5b1

Bricks Script:
https://gist.github.com/anonymous/22db9e4d173fb116d69eeafdb559a02b

1 Like

What version of Unity are you using? Application.LoadLevel has been deprecated by the SceneManagement package. https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html

public void LoadNextLevel() {
	Scene current = SceneManager.GetActiveScene();
	int newindex = current.buildIndex + 1;
	Debug.Log ("New Level load: " + newindex);
	SceneManager.LoadScene(newindex);
}

Also this should probably be in the Unity topic rather than Lounge as it’s Unity specific.

2 Likes

I have relocated this topic on @Alfonso_D_addio’s behalf.

1 Like

Unity 4.6.9

Thank @Rob

1 Like

Can you pop up a screen shot of the error please…

This is Ben’s full source, compare what you have to that. https://github.com/CompleteUnityDeveloper/05-Block-Breaker/
From what you’ve posted above, it looks like your LevelManager does have a public LoadNextLevel() method, so there’s probably something weird in the way it’s structured - if you want to commit your entire project to GitHub I’d be happy to look it over.

Thanks for the screen shot…

Edit

ooooooooooooooooh! I have just spotted something, wish I’d seen this first!!

At the top of the screen it says you have TWO build errors. If one of those is within LevelManager and you added the LoadNextLevel() method to the script after this (or if the error is within it) MonoDevelop will not have been able to build a new dll which contains the changes to the file, e.g. LoadNextLevel() method.

So, what would be really useful here now is to see what both of the errors are, this is clearly one of them, but I suspect that the one I can’t see from the screen shot may be stopping your build process which is causing the second error (the one in your screen shot).

I moved the above which was at the bottom of my post as I think this may be more relevent

There’s nothing that really jumps out which I can spot… but there are a few things you could try…

The first thing I’d give a go would be in your Start() method. This is where you are grabbing the LevelManager, so after line 11 I would add a line which outputs to the console a value from the levelManager variable, doesn’t really matter what, just so that you can be sure it’s there.

Next as I was typing levelManager as soon as you hit the dot, if you have intelli-sense working, you should see a list of variables/properties/methods which are in scope, is LoadNextLevel() in that list? Based on the error I wouldn’t expect it to be, but it’s worth checking what is available.

After this I would probably comment out the LoadNextLevel() method in LevelManager and add another method, making it public, saving the file and then return to the step above and see if this new method is displayed, if it is this is good, if it isn’t this is not good! If it’s displayed, go back and uncomment the LoadNextLevel() method, save the file and again return to the step two above and see if it appears in the intelli-sense now.

It would be worth building the code if this is an option in MonoDevelop, I honestly can’t remember as I use Visual Studio. Within Visual Studio there are also options to Clean the solution which will remove all of the built dlls and cache files, this can be very useful when this sort of problem occurs, you ensure you get a fresh build.

I’d also be checking to see if there were any oddities where things may have been renamed, it’s not obvious from your screenshots and code, but renaming script files within Unity doesn’t (or certainly didn’t, haven’t checked recently) rename the Class in the script.

Are you using Prefabs? If so, where are the scripts attached, to the Prefabs or to the objects in the hierarchy?

As per @ninjachimp, I would be more than happy to take a look at the whole project if you are able to pop it up somewhere we can access it.

1 Like

I don’t know why but now it’s working.I rewrote the same code and now it’s okay.
thank you @Rob @ninjachimp

2 Likes

Glad you got it all sorted :slight_smile: