Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sardos · Nov 16, 2018 at 11:57 AM · loadload scenesave scene

How to load player last scene visited

Hello guys! please i need help to understand how to save and load the last scene that player has played, It can be even playerpref anything will be fine! If that is important the game is set up like that, for example we have 3 zones A, B, C and so on. A connected to B, B is connected with A and C, and C with B. ( There are no "completed level" ) What i need to do and have? I can not find a guide for that specific thing... ... Please! Thanks in advice!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image losingisfun · Nov 16, 2018 at 12:12 PM 0
Share

Well you can't save an entire scene exactly the way it is with one line of code, you'll actually need to save all of the data and variables basically, store them, and make your own method of recreating the scene in the exact state it was saved in. It's not all that hard really, but if you explain how your game works perhaps we can offer some suggestions

avatar image Sardos losingisfun · Nov 16, 2018 at 12:51 PM 0
Share

Thanks! I forgot to say that is in 2D, pretty close to the unity Explorer 2D game kit! ( But without the tilemap, the whole scene is drawed in one png with some sprites in addition), i have already set up dont destroy on load on character prefab, everything works fine, i can go on and back through scenes, but for some reason i dont know why im able to Save only in one scene... Even using other saves utility... ... If you need to know more just tell me

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tomer-Barkan · Nov 16, 2018 at 01:47 PM

Whenever a scene is loaded, save it in player prefs. Then have a method that will load that scene.

 private void Awake()
 {
     SceneManager.sceneLoaded += OnSceneLoaded;
 }

 private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
 {
     PlayerPrefs.SetString("_last_scene_", scene.name);
 }

 public static void LoadLastScene()
 {
     SceneManager.LoadScene(PlayerPrefs.GetString("_last_scene_"));
 }

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sardos · Nov 16, 2018 at 02:31 PM 0
Share

Thank you, i guess that's what i wanted! I will try that once i come back home! Any other advice on how should i use It?

avatar image Tomer-Barkan Sardos · Nov 16, 2018 at 04:25 PM 0
Share

Hmm, attach this script to an object that is in your first scene, and add a check in Awake to make sure that it doesn't get executed more than once (use a static bool, and set it to true after registering to sceneLoaded).

Then simply call the static LoadLastScene whenever you want to load the last scene.

avatar image Sardos Tomer-Barkan · Nov 24, 2018 at 01:44 PM 0
Share

sorry for the late reply, i've got fever and i doesn't feel quite well! i'm feeling a bit alright just today... ... I've achieved what i was trying to do! Thanks <3! I have some more question now, should i ask here or i have to open a new post? ( I would like to know how to merge this with enemies death, dialogue and things like that ) thanks again!

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

97 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving your scene and location in game? 1 Answer

Unity how to find load time? 1 Answer

Go back and forth between procedurally generated levels? 2 Answers

Creating a Save/Load game 2 Answers

Loading screen with long-running CPU-heavy Awake() 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges