Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Scene Saveing

Discussion in 'Scripting' started by LuftWaffle3, Mar 9, 2018.

  1. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    I don't know if I'm wording this right.
    But I'm new to unity, I was wondering if you can save the scene of the last one I was on because I have 2 scenes on is the game that I'm making one is the game and the other one is a shop scene and I want to reload what I was doing in the original scene (like if you were to pause a game then unpaused it and stayed in the same place as you where you were before hand) which is the game scene does anyone know how to do this.

    Thx in advance :)
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,113
    When loading a scene using SceneManager.LoadScene, you can pass then optional LoadSceneMode parameter. By default, loading a scene first unloads the current scene. But you can set this to Additive, which will load your second scene on top of your first scene. When you're done on your Pause screen, you can call UnloadSceneAsync to destroy the Pause screen, and resume things in your first scene.

    However, getting that to all work cleanly can be tricky, since both scenes will be loaded at the same time. It may be less work overall to record the positions of everything in your first scene, and just rebuild the scene with that data when unpausing.
     
  3. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    would you have any code examples
    also would it work with buttons?
     
    Last edited: Mar 12, 2018
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    My approach to this(if you don't need an actual 3d store to walk around in) is just pause the game and overlay the shop as UI on top, when done disable shop ui and resume game
     
  5. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    Thats what im trying to do i just dont know how to go to the shop person and return to the last spot i was before i open the new scene for the shop im also using buttons so if you have any code that could help me that would be great
     
    Last edited: Mar 12, 2018
  6. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    What I'm saying is don't switch scenes, when you need to enter the shop pause the game and instead of displaying a pause screen display a shop interface
     
  7. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,113
    As SparrowsNext said, if your Shop scene is really just some 2D UI, and not a full 3D scene, then the following approach is pretty simple, and I've used it before. These are basically the steps:
    • Put your Shop UI onto a single game object, and make it a prefab by placing it into a folder named Resources.
    • When you want to show the shop:
      • set "Time.timeScale = 0;"
      • Instantiate the Shop prefab (Resources.Load(), then GameObject.Instantiate()
    • When you want to resume the game, call GameObject.Destroy() on the Shop game object, then set "Time.timeScale = 1" again.
    One caveat is that your Shop menu would need to work when timeScale is 0. If you're doing anything based on Time.deltaTime in your shop menu, you might want to use Time.unscaledDeltaTime instead, which continues to change while the game is paused.
     
  8. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    upload_2018-3-12_11-18-36.png
    this is an example of what i want
     
  9. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    How would I do that sparrowsnest?
    Mainly dont understand how to pause it and make a UI pop up
     
  10. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Do you have pause in your game?

    Its basically just setting timescale to zero and activating a UI game object.

    I'm on moblie, I'll be home in an hour or so I'll show you an example
     
  11. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    Ok ill wait to see because it is still puzzling to me
     
  12. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I think this may prove of more help then a code snippet.


    This guy(Brackeys) is excellent for beginners, if you want some more advanced stuff check out "quill18creates"
     
  13. LuftWaffle3

    LuftWaffle3

    Joined:
    Mar 9, 2018
    Posts:
    15
    Thx this was very help full