Level script is missing upon hitting start button

When I hit the start button (after playing), my level script turns up missing (after not having the start button work). Looked in the discussions but haven’t seen this problem. Maybe I’m missing something. Please help. Thank you.

Hi Ossie_Spears,

Welcome back to our forum! :slight_smile:

Is your Level script a “singleton”? Or does something destroy it during runtime?

1 Like

It seems to destroy itself during runtime. Each time that I’ve added the Level script, then hit play, the script immediately disappears from the Level. I do not see any destroys from the look of things, if I understand “singleton” correctly. I do see in the Event System that under First Selected, there is none. Could this be the problem? That’s just a shot in the dark. Thank you for your reply.

Unfortunately, that has nothing to do with destroying a script, that serves another purpose.

Could you please copy-paste your Level script? I checked the Git from the lecture you are posting this and there should not be any reason for it to be destroyed.

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

public class Level : MonoBehaviour
{
public void LoadStartMenu()
{
SceneManager.LoadScene(0);
}

public void LoadGame()
{
    SceneManager.LoadScene("Game");
}

public void LoadGameOver()
{
    SceneManager.LoadScene("GameOver");
}

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

}

I don’t see any reason as to why your script should be destroyed.

I think I understand what is going on: you are pressing the Start UI Button, Right? Like, the button from the main menu of the game. If that’s the case, is not that script is disappearing, is that you are changing scenes, then what is probably happening is that in that new loaded scene, you simply forgot to put the script on the Level object.

If your object is a prefab there’s also a chance that you forgot to save the changes of that prefab after adding the script, to avoid that and also avoid future issues, go directly to the prefab, inside the Assets folder, be sure that it has the script attached, if it doesn’t then open the prefab by double clicking and attach it. Be sure to check your Level objects you have in each scene, because they might have a duplicate script.

Yee, it was not saving the script inside the prefab. Thanks a lot Yee!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms