Search Unity

Question how do i move between scenes, while keeping progress in them

Discussion in 'Scripting' started by puddleglum, May 18, 2022.

  1. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    412
    i have two scenes and i would like to move between them without the player losing all progress in one of them. is there any way to do this?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    Either implement a save/load system or use additive scene loading so you don't unload the previous scene.
     
  3. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    412
    ok thanks, ill look into implementing a save/load system and also i had no idea additive loading was a thing :p thanks
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Not only is it a Thing, but it is a Beautiful Thing(tm). Here's a blurb to get you going:

    Additive scene loading is one possible solution:

    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6630961
    https://forum.unity.com/threads/right-way-for-performance-divide-scene.1023673/#post-6754330

    https://forum.unity.com/threads/problem-with-canvas-ui-prefabs.1039075/#post-6726169

    A multi-scene loader thingy:

    https://pastebin.com/Vecczt5Q

    My typical Scene Loader:

    https://gist.github.com/kurtdekker/862da3bc22ee13aff61a7606ece6fdd3

    Other notes on additive scene loading:

    https://forum.unity.com/threads/removing-duplicates-on-load-scene.956568/#post-6233406

    Timing of scene loading:

    https://forum.unity.com/threads/fun...ject-in-the-second-scene.993141/#post-6449718

    Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It's a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

    Two similar examples of checking if everything is ready to go:

    https://forum.unity.com/threads/daily-events-and-content-changes.1108202/#post-7143713

    https://forum.unity.com/threads/uni...on-before-other-scripts.1153739/#post-7401794
     
  5. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    412
    i will definitely look into these links however i have questions on you prefab advice, 90% of all the elements in my scenes are prefabs, environment elements like trees lamps fences etc. there are some things that only appear in one scene, i have a puzzle level with buttons and only in that scene are the buttons used, (the buttons are prefabs.) most everything else is used a lot, maybe not in multiple scenes, but at least 100 times in each scene, should I unpack these?
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,930
    That's not what Kurt is quite saying.

    What they more so mean is, if, for example, your player is done via an additively loaded scene, then you don't need to make a prefab out of your player.

    What they're saying doesn't so much apply to general level decorations. You don't need to unpack all the prefabs you drag and drop around; kinda defeats the purpose of prefabs.
     
  7. puddleglum

    puddleglum

    Joined:
    May 11, 2020
    Posts:
    412
    so basically dont prefab your player?
     
  8. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,930
    It was an example to explain the concept.
     
  9. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    No you can totally prefab your player... think of it this way:

    You have a scene open... you do some work and make a "thing"

    You can drag that "thing" out and make a prefab

    This lets you put that same "thing" in every scene.

    But you must be careful that if that "thing" is in SceneA and SceneB, you make changes to that thing in SceneA, you must APPLY those overrides to the prefab, otherwise SceneB won't have those changes, only SceneA.

    Prefabs are perfect for things like doors and switches and things you use all over the place.

    But for something like a player, I usually do not make a prefab: I prefer actually to load him into an additive scene, then when he dies, unload and reload the scene... but you certainly COULD use a prefab for the player too.

    Unpack basically breaks the links from the scene to the prefab and freezes it in the scene. All future work done to the prefab won't show up in the scene where you unpacked it. You probably don't want that unless you ARE going to only keep the "thing" in one scene.