Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 GoodVibes_IndieGameDeveloper · Aug 07, 2017 at 06:31 PM · save datasaveloadlevel select

Save And load Level Data in a game with one game scene and multiple levels saved as prefabs

hey, I'm trying to find the best way to control the level management of my game. i have only one game scene, and the levels are saved as prefabs (every prefab has inner gameobjects and a different design - not just a script) every level has some variables - isStar1Completed, isStar2Completed, bestTime, timeForStar and few more

i need to load the levels data from the level select scene, to show the user the level goals and his progress and when the user select a level to play, I need to pass the level id/name to the game scene and there to instantiate the chosen level prefab

is it bad to store a lot of prefabs in the resources folder? has anyone tried to use the Asset Bundles and can it be good for my purpose?

I would really appreciate any idea on how to approach this thanks

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by agray427 · Jan 15, 2018 at 07:56 PM

I've heard Resource Folder calls are bad, but I don't see the harm in using them for this. You will only be making one call at a time, so it's not bad. Here's what you need to do. You need to create a class called LevelData. Store the information about stars, time, and other stats like that onto it. You also want to store the relative path of the Prefab as a string in the class as well. You will then have a list of these that need to be saved and loaded from a GameManager class which inherits from MonoBehaviour. I think the easiest route for you is to have the GameManager class have a list of LevelData, make sure it is marked with [System.Serializable], and then you can edit these values to be whatever you want within the Inspector. GameManager will serialize all of this data, so that's not a problem, however these changes won't persist. To get the data to persist, you need to save these changes to a file in some directory; I recommend Application.persistentDataPath. Whenever you start the game, it should check to see if the file exists. If it does, you will load the list from the file. This will override all of the settings you had made in the editor, which is what you want. That means the data persisted. The data you create in the editor should only be the INITIAL list. You will have issues of adding new levels and stuff, but these can be avoided by creating a custom loader. For example, you could load the list that's in the file, check to see if the current list already has a reference to the same scene, and override it's values. That way, if you added something in the editor after already saving data that the change wasn't apart of, it won't override your new levels and stuff that you're trying to add to the game. I hope this helps, but I'm here if you have more questions!

Comment
Add comment · Show 1 · 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 agray427 · Jan 15, 2018 at 07:57 PM 0
Share

For advanced serialization, you can always read over my blog post here: https://graymattertutorials.wordpress.com/2018/01/15/serialization-with-json-net-in-unity-3d/

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

68 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

Related Questions

How can i save the games inventory? 1 Answer

How do I make a basic easy Save and load function with JavaScript 1 Answer

Save/Load System not working 0 Answers

How do i change my save "Total Coin" everytime i get more coins. 0 Answers

Save Game Sceenes user quit aplication, Can I save the scene as a whole while leaving the game? 0 Answers


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