Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

I can only switch scenes once and then never again in play mode

Discussion in 'Editor & General Support' started by greenSprite_, Jul 26, 2021.

  1. greenSprite_

    greenSprite_

    Joined:
    Jul 23, 2021
    Posts:
    1
    I am using the SceneManager.LoadScene function to do it both ways (pressing play in the menu to start the game and pressing the exit to menu button in the pause menu to return), but I can only switch scenes once, and then if I try to do it again nothing happens. Not getting an error either. I'll include my script for switching scenes as well as my pause menu in case that is part of the problem (and yes I know I need to switch the spawning from the game manager script)
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    You can also put in Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494