Public GameObject not appearing in the inspector

Hi,

I’m having a bug where all of my scripts (dozens) are not working, because I can’t drag and drop a gameobject in the ‘public GameObject’ variable. Can you guys help me out? I’ve had all my code checked and there are no errors in the console.

One of my scripts:

using UnityEngine;
using UnityEngine.SceneManagement;

public class Pause : MonoBehaviour
{
    //I also tried:
    //[SerializeField]
    //public GameObject PauseMenu;
    
    //Current code:
    public GameObject PauseMenu;

    //I also tried:
    //[SerializeField]
    //public GameObject ToMainMenu;

    //Current code:
    public GameObject ToMainMenu;
    
    public static bool isPaused;
    
    void Start() 
    { 
        PauseMenu.SetActive(false);
    }

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            if (isPaused)
            {
                Continue();
            }
            else
            {
                PauseGame();
            }
        }
    }
    private void PauseGame()
    {
        PauseMenu.SetActive(true);
        Time.timeScale = Mathf.Epsilon;
        isPaused = true;
    }

    private void Continue()
    {
        PauseMenu.SetActive(false);
        Time.timeScale = 1f;
        isPaused = false;
    }
    
    public void Quit()
    {
        Application.Quit();
    }
    
    public void ToMainMenuScene()
    {
        Time.timeScale = 1f;
        SceneManager.LoadSceneAsync("Mainmenu");
        isPaused = false;
    }
}

Thanks in advance for the help!

@partimelhero

‘Pauzeren’ means Pause. I translated the code for you guys to be able to read, so in the actual script there are no errors regarding any language errors

Personally, I think it has something to do with corrupted settings/files.
I’ve tried to copy my assets/hierarchy into a new project, but still the same bug. But when I open a new project without any of my assets/hierarchy, ‘public GameObject’ works as it should be.

Is there anything I can try to fix this weird bug?

Your class is named “Pause” (also might be because of your translation) and your script is Pauzeren.
Change the class name to “Pauzeren” and see if that works. I think class and script names have to be match. If it doesnt fix the issue:

You said that you have dozens of these glitched scripts.

  • Do they all happen to bug out when attached to a specific gameObject?
  • Is it just in a specific scene?
  • On what Unity version do you code?
  • Is any other script working? (if yes, what is the core difference those scripts?)

You definitely should try what @partimelhero said.
And maybe set your unity version to the next LTS?

I think I had a similar issue like this, because I moved all of my scripts from one folder to another once and somehow did that wrong. Just making new scripts, copying the content of the old ones and pasting them in (with the matching class name) worked for me back then.

You Tried To Use “public GameObject PauseMenu” Your Problem Is That PauseMenu Needs To Be Lowercase In Otherwards The Solution is “public GameObject pauseMenu” With A Lowercase “p” THIS APPERARS TO BE WRONG DO NOT USE THIS CODE