Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

19 Neutral

About ethancodes

  • Rank

Personal Information

  • Role
  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. ethancodes

    GameManager destroyed error

    Actually I've somewhat got it figured out. Maybe. I moved the Managers object to the Start scene instead of the level1 scene. Now when I start, I get two errors. They are both for Awake functions on two different managers. The errors are caused because the stuff they are trying to reference don't exist until Level1 scene is loaded. However, errors aside, the game will now switch between scenes just fine without losing the reference to the game manager. I'm gonna try to do a little reworking on these couple of methods and see if it works.
  2. ethancodes

    GameManager destroyed error

    Here is a picture of my console when switching from the MainMenu scene to the Level1 scene. You can see the MainMenu state's Update function being hit. The "This is a game manager" is the update function of the GameManager. So then we hit MainMenu state's OnDeactivate, and the GamePlay state's OnActivate. We can see the game manager update is still being hit. Then the Update function of the GamePlay state. and finally we see the GameManager being destroyed. That is when the reference ("This is null") is lost in the Managers game object. However, right after that we can see the GameManager update is getting hit still. So I'm not sure if it is 1.Destroying the old game manager and making a new one, or 2. Keeping the old game manager and destroying the new one. It's hard to say, but I guess number 2 since it's losing the reference. But I have no idea how it could be doing that since the singleton is in place and DontDestroyOnLoad should be preventing that.
  3. ethancodes

    GameManager destroyed error

    I have not... You mean just to see when it's getting called? Or if it is getting called? I could certainly try this. Should we expect to see it called once, when it tries to make another one and finds that there is already one made so it gets destroyed? Is that what you are suggesting we try to find out? So I just found this: https://forum.unity.com/threads/missing-reference-after-reloading-a-scene-but-the-referencing-object-still-exist.383648/ Sounds like a few people here had the same issue and had to unsubscribe from global events. I'm not entirely sure what that means or how to do it?
  4. ethancodes

    GameManager destroyed error

    Still have not found a solution to this, if anyone has any more insight I would be truly grateful
  5. ethancodes

    GameManager destroyed error

    I put a debug.Log in the Gamemanager class and even when the Manager is saying it's null, it is still firing the debug.Log every update from the GameManager. I tried to put a function in the Managers class that I could call after loading a new scene to find the GameManager component again, but still got the same error. Any other ideas? I've posted this in a few other places as well hoping to find something. I've pretty well run out of ideas myself.
  6. ethancodes

    GameManager destroyed error

    Does it matter which scene the Managers game object is in? I have it in the Level_01 scene simply because that's where I'm always working in for most of the game so it makes it convenient to have in there so I don't have to switch between scenes for it. Then when the game starts it loads the Start scene (main menu). I don't believe it should be a problem though since that game object should be persistent anyways right?
  7. ethancodes

    GameManager destroyed error

    Sorry I put in my edit on the previous post that I did try that and it did not work. Error was the exact same. I tried it from both the individual scripts of the various managers, and also as gameObject.GetComponent<> on the Managers script.
  8. ethancodes

    GameManager destroyed error

    So I put a Debug.Log in the Managers script in the Update function that checks Managers.Game == null. If it is, it puts a message in the Console. When the game starts up and pulls up the Menu scene, it works fine. However, it is returning null as soon as we switch scenes. So, important question that maybe someone had previously answered incorrectly. I was told I only need to put the DontDestroyOnLoad on the Managers script and since everything else is on that, they would also not be destroyed on load. Is it possible that I need to put DontDestroyOnLoad on each script? EDIT: I tried this and it did not make a difference. Still trying to figure out the issue, I have attached the error I am getting.
  9. ethancodes

    GameManager destroyed error

    I will get the exact error text when I get home tonight, and I can certainly try to set the order, but if this is the problem, shouldn't it be getting an error when the GetComponent fails? Not later when it tries to call a method on the GameManager? It's also not the first time the GameManger is being called on as it is already being used to load the Menu state when the game starts, and then called again to move from the Menu state to the Gameplay state. So I'm certainly using it a few times before I'm getting this error.
  10. ethancodes

    GameManager destroyed error

    No I apologize that was my mistake. It says Game Manager has been destroyed. I edited the original post.
  11. I've got a state machine set up that I'm having an issue with. I have a Start scene, a Level_01 Scene, and a GameOver Scene. Each scene has a corresponding state. When the game starts, it sets the game to the Start scene. When I click the start button, it loads the Gameplay state. The game plays fine, but when you lose, the GameOver state does not load, the game continues to run, and I get one error that says the Game Manager has been destroyed and I am still trying to reference it. I have my managers set up on a Singleton pattern and I'm not sure how it's getting destroyed. This is my first time using both the state machine and the singleton, and I also have very little experience switching between scenes so I may be doing something simple wrong. The main thing I can tell you is that the currentState variable is coming back as null when I go to hit the GameOver state, and that the code is not even getting far enough to hit the OnDeactivate for the GamePlay state (probably because currentState is null). I'm really out of ideas on this one and haven't been able to find anything useful online. Hopefully someone can show me what I'm doing wrong. Thanks! //Managers object code: public class Managers : MonoBehaviour { public static Managers instance = null; private static GameManager _gameManager; public static GameManager Game { get{ return _gameManager; } } private static UIManager _uiManager; public static UIManager UI { get{ return _uiManager; } } private static LevelManager _sceneManager; public static LevelManager Level { get{ return _sceneManager; } } private static BoardManager _boardManager; public static BoardManager Board { get{ return _boardManager; } } private static PickUpManager _pickUpManager; public static PickUpManager PickUp { get{ return _pickUpManager; } } private static SoundManager _soundManager; public static SoundManager Sound { get { return _soundManager; } } void Awake () { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); _gameManager = GetComponent<GameManager>(); _uiManager = GetComponent<UIManager>(); _sceneManager = GetComponent<LevelManager>(); _boardManager = GetComponent<BoardManager>(); _pickUpManager = GetComponent<PickUpManager>(); _soundManager = GetComponent<SoundManager>(); } } //GamePlayState code, other states are basically the same public class GamePlayState : _StatesBase { public override void OnActivate () { Debug.Log("GamePlay OnActivate"); Managers.Level.LoadLevel("Level_01"); Managers.Game.isGameActive = true; } public override void OnDeactivate () { Debug.Log("GamePlay OnDeactivate"); Managers.Game.isGameActive = false; } public override void OnUpdate () { Debug.Log("GamePlay OnUpdate"); } } //GameManager code public class GameManager : MonoBehaviour { public static MonoBehaviour monoBehaviour; public bool isGameActive; private int level = 50; private _StatesBase currentState; // Use this for initialization void Awake () { isGameActive = false; InitGame(); monoBehaviour = this; } public _StatesBase State { get { return currentState;} } void InitGame () { Managers.Board.SetupScene (level); } public void SetState (System.Type newStateType) { if (currentState != null) { currentState.OnDeactivate (); } currentState = GetComponentInChildren (newStateType) as _StatesBase; if (currentState != null) { currentState.OnActivate(); } } void Update () { if (currentState != null) { currentState.OnUpdate(); } } void Start () { SetState(typeof(MainMenuState)); } } //The load level method from the LevelManager public void LoadLevel (string name) { SceneManager.LoadSceneAsync(name); Brick.breakableCount = 0; }
  12. I removed the UnloadSceneAsync because apparently when you LoadScene in Single mode it automatically gets rid of the other one so the problem was it wouldn't unload the original scene yet because I was trying to do it before the other scene was loaded.
  13. @Shaarigan I've got an on going issue related to this problem. I added some Debug.Logs in all my state methods so I could see when they were being called. When I start the game and I'm in the main menu, it seems to be working right. Then I hit start and the gameplay screen flashes for a second then goes back to the main menu. After that the debug.Log keeps alternating betwen the Gameplay State update method and the MainMenu State update method. I have no idea how they could both be active at the same time. I've tried all kinds of stuff. I do get this warning (see below) but I'm not entirely sure what it's about. I took the UnloadSceneAsync out of the OnDeactivate method on the MainMenu and that got rid of the warning but didn't change the behavior. Any ideas what's going on here and what the proper way to dispose of the MainMenu scene would be when the game starts?
  14. Ok perfect, thank you!
  15. Got this figured out. My Managers object was not instantiated in the Start scene. I have a question though. Obviously I only ever want one Managers object, which should contain all my managers. In the Hierarchy panel, do I just put it in one scene and then make sure I always start the game from that scene? Or do I put one in each scene?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!