Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
5
Question by SrBilyon · Jan 09, 2012 at 09:32 PM · saveloadgame-state-management

Game and Level State Logic

I'm trying to find the best way to implement a general script that will temporarily store variables from the player, inventory, level specific scripts (possibly), etc. Currently, I have a script that stores all the information of my player (and is connected to my player's prefab) as well as the contents of the inventory.

I haven't thought of a way to program/collect information from each level (mainly because each level will have there own set of variables.

I created a graph of the logic that I intend to use, everything with an asterisk I'm not entirely sure how I should implement it.

alt text

So, is this a good implementation? Should I have a "Game State" class? And any specific way I can do a "Temp Save" Container? I would also like to "prepare" this information when I need to save.

Any advice would be appreciated.

Comment
Add comment · Show 3
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 nastasache · Jan 09, 2012 at 10:02 PM 1
Share

Impressive. I like this kind of presentations. You can collect/keep information between levels using an object having DonDestroyOnLoad().

avatar image SrBilyon · Jan 09, 2012 at 10:11 PM 0
Share

Thanks. I have the DontDestroyOnLoad for the other scripts, just need info on setting up one central script efficiently to contain all this.

avatar image nastasache · Jan 09, 2012 at 10:32 PM 0
Share

I don't know the optimal way of implementation. I am looking also for a tutorial about this. In my simple way, I have defined few variables - keeping major information (like items found, health, score, current level id) - into as component of 'GameState' simple as possible object, non-destructible and instantiated in level 0. These vars values are changed over the levels, showing the result at the end of the game. Saving/Loading game @ level n it's different issue (I don't know if your workflow above it's about save/load game on/from disk or store/retrieve game states during of game play with no saving/reload levels). I am looking for solutions too.

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by swisscoder · Jan 10, 2012 at 05:59 PM

If you work with interfaces (c#), you could define an interface for your storing/loading.

Then you could replace the implementation in each level based on the specific needs.

For example:

 public interface ISavegameManager { 
 yourSaveGameDataStructure load();
 void save(yourSaveGameDataStructure savegamedata);
 }

then you could go and implement a different SavegameManager for every scene:

 public Level1SaveGameManager : ISavegameManager
 {
    public yourSaveGameDataStructure load()
    {
        //read data from whatever datasource you stored it..
    }

    public void save(yourSaveGameDataStructure savegamedata) 
    {
        //save your data to whatever source you like
    }
 }
 

In the end you can simply exchange the SavegameManager on your "global" GameManager Script on level loading, or whenever you need to change it.

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

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

7 People are following this question.

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

Related Questions

How to script a Save/Load option on IPhone? 1 Answer

Saving Game Problem 1 Answer

PlayerPrefsX - Not Saving? 1 Answer

Best way to save procedural world/mesh? 0 Answers

Save and load data with Javascript... 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