• 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 pborg · Jul 25, 2013 at 09:49 PM · serializationunity serializer

Loading problems with unity serializer

I'm using Unity Serializer (and I'm using this community because it gets more traffic) to save board game configurations in a mode where you can set the tiles of the game and load them later to play with that configuration any time. In the builder scene this function is called to save:

 function savetopology(levelname : String)
 {
     print("# of saved games:" +  LevelSerializer.SavedGames.Count.ToString());
     LevelSerializer.SaveGame(levelname);
     //add to the count
     var lctemp : int = PlayerPrefs.GetInt("levelnumber");
     PlayerPrefs.SetInt("levelnumber", lctemp+1);
     print("levelnumber =" + PlayerPrefs.GetInt("levelnumber").ToString()); 
     print("save level called");
     print("# of saved games:" +  LevelSerializer.SavedGames.Count.ToString());
 }

In this function LevelSerializer.SavedGames.Count is never updated. It's always 1. The problem right now is that the load section only recognizes the first two saves. After that the saves don't take. When I reload the game to the previous scene, the first two are the only ones there. Here's the loadgui.

 if(PlayerPrefs.GetInt("levelnumber") > 0)
     {
         print("displayinglevels");
         if(leveldisplaystart > 1)
         {
             if(GUI.Button(Rect(0, Screen.height/2, Screen.width/5, 50), "^"))
             {
                 leveldisplaystart = leveldisplaystart - levelsperpage;
             }
         }
         var counter : int = 0;//*
         var displaycounter : int = 0;
         
         for(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName]) //*
         {
             if(counter >= leveldisplaystart && sg.Name != "levelname")
             {
                    if(GUI.Button(Rect(0, (Screen.height/2)+(displaycounter*( (Screen.height/2-100) /levelsperpage))+50,Screen.width/5, ( (Screen.height/2-100)/levelsperpage )),sg.Name))
                    { 
                     tobeloaded = sg;
                   }
                 print(sg.Name + " found");
                 displaycounter++;
             }
             counter++;//*
         }
         
         if(leveldisplaystart < PlayerPrefs.GetInt("levelnumber")-levelsperpage)
         {
             if(GUI.Button(Rect(0, Screen.height-50, Screen.width/5, 50), "V"))
             {
                 leveldisplaystart = leveldisplaystart + levelsperpage;
             }
         }
         
         //load button
         if(tobeloaded != null)
         {
             if(GUI.Button(Rect(50, Screen.height - 100, 100, 50), "Load Level"))
             {
                 savecharacters();
                 //Gametempdatabase.startinginfocon = icstart;
                 tobeloaded.Load();
             }
         }
     }

levelnumber is my own counter to keep track of the number of levels made. This index of savedgames is also being used to load a game saved in progress named "levelname"; not elegant naming, but it works. Once again, the problem is that the saved games after the second one are not showing up on the loading screen and likely not in savedgames.

Comment
Add comment · Show 6
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 pborg · Jul 29, 2013 at 04:58 PM 0
Share

also- my particle systems change their size of their particles upon reloading.

avatar image whydoidoit · Aug 21, 2013 at 12:02 PM 0
Share

SavedGames are subject to a limit. You probably want to manage your own saves using SerializeLevel and store the result yourself. The SaveGame system is very high level and has very specific functioning around that.

avatar image yoyo · Aug 22, 2013 at 06:55 AM 0
Share

Is LevelSerializer part of an Asset Store package? I don't see it mentioned in the script reference.

avatar image whydoidoit · Aug 22, 2013 at 07:02 AM 0
Share

Yep, UnitySerializer, written by me :S

avatar image yoyo · Aug 22, 2013 at 07:17 AM 0
Share

Aha, this one -- https://www.assetstore.unity3d.com/#/content/3675. Cool.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Issues when using Unity Serializer 1 Answer

Is it possible to use DataContractJsonSerializer? 2 Answers

List Type Mismatch 0 Answers

How do you serialize things on Windows Phone? 0 Answers

How to export Serialized Data with my Build 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