SceneManager.LoadScene("Game"); not working

Hello, so i have been using unity 2022 something. i recently upgraded to 6000.0.7f1 and in my MainMenu script i am getting an error saying: “‘SceneManager’ does not contain a definition for ‘LoadScene’ (CS0117)”
Can anybody help? The code worked fine just yesterday.

This is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene(“Game”);
}

public void QuitGame()
{
Application.Quit();
}
}

Sounds like you made your own class named “SceneManager” and the compiler things you are trying to use your class instead of Unity’s. This is a pretty common mistake for beginners.

3 Likes

It’s also pretty common in general to name classes “ThingManager”. :roll_eyes:

Litmus test: omit the “Manager” suffix. Does the class name still make any sense?

If not, try to come up with a different name that does make the intent clear! Because “Manager” provides next to no meaning or intent besides ‘contains code related to ’.

The “Manager” suffix is the equivalent to the singleton antipattern when it comes to naming classes. Let’s make everything a singleton (everyone naturally be like: :hushed:) vs let’s call everything a “Manager” (everyone shockingly be like: :sunglasses:). You stop thinking about these things, and create a total, unrecoverable mess rather quickly.

For instance said “SceneManager” is sort of okay-ish because it has few public methods where it wouldn’t make sense to split this into separate classes like SceneLoader, ScenesCollection and SceneEvents and its relatively rare use doesn’t warrant a split either.

But you will already notice that these three names each provide far more intent - you naturally know what to expect them to do and provide. SceneManager however is an open-ended class name, in fact I feel merely by its name it’s already violating the single-responsibility principle.

These “managers” have litterally (accidental pun) become the de facto standard for writing ANY code related to a broad concept into a single script. There are few instances where a “Manager” class makes sense, and even these are debatable and can largely be attributed to “tradition”.

Just another Anti-Manager educational article. :smile:

1 Like

Thats weird. This script worked just fine, and the script is not even mine. I watched a tutorial and it always used to work. IDK whats happening this all happened after i switched to unity 6

I Figured it out!

What did you do? How did you fix it?