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
0
Question by Waldy · Sep 14, 2013 at 10:56 PM · save scenescript loadinggame save

Unity Serilizer taking to long to Save/load?

I have had alot of problems with Unity Serializer recently and one of them was long saving and loading times. All i have in my game is a island and alot of tree's Unity Serializer is tracking 759 objects and it now takes to long to save and load.

Any ideas,

Oh also how do you save a object that was created in runtime??? ;)

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
Best Answer

Answer by OperationDogBird · Sep 14, 2013 at 11:23 PM

You cannot save an 'object' while the game is playing. You can save any data that represents the current state of that object (bool, float, int, string).

Im not exactly sure what you mean by unity serializer saving, do you mean player prefs? I suggest using a different method of saving (player prefs writes to disk every time you Save(), thus long save times).

I use Preview Labs Player Prefs, very fast saving because you just add/modify keys in a hash table, then when you click quit in the game just call Flush() and it will write to disk.

//EDIT ( Additional information regarding saving simple data types)

This is where your logic will come into play. There is a million and 1 ways to do what you want, my way will more than likely not be the best solution or even a decent solution :P, but i will try to walk you through a semi-simple object example.

SwampTreeVersionA - (lets pretend this is one of your tree types)

You first need to create the global identifier key for this type of tree. Maybe adding a prefix is the best way? I will take that route since string operations are heavy, and the shortest identity of a string is the first unique char set.

"00_ST_VsA" - this will be our global identifier key prefix for the first instance of 'Swamp Tree Version A'

(float) 00_ST_VsA_Pos_(X,Y,Z) - these three values(suffix X,Y,Z) will represent the position (your trees probly dont move, but for future reference maybe?) //Same for rotation via local euler angles //( x, y, z, w ) for quaternion

(int) 00_ST_VsA_state - enum state of the tree (full, chopped1, chopped2, dead)

So thats all well and good, but how do we actually save that data?

Each piece of data is stored in a hashtable, which consists of Key-Value-Pairs.

 {"String", "StringValue"} // string
 {"Bool", false}           // bool
 {"Single", 0.03f}         // float
 {"Int", 22}               // int

You can only save the 4 fore-mentioned types, these will be our values. The key to access each value will be a unique identifying string.

Saving these values will go hand in hand with loading the saved values, as would encrypting a file go hand in hand with decrypting that file.

So lets save our swamp tree!

We will save the current state of the SwampTreeVersionA ( enum represented by an int value )

 PreviewLabs.PlayerPrefs.SetInt("00_ST_VsA_state", (int)yourTreesState);

Technically that is all you really need for saving a simple trees state. Since a tree doesnt move or rotate (well, most of the time). When you move on to saving classes the data can be a bit tougher to manage, but with a bit of thought and good planning, you will find a way to almost automate the entire saving process in a single method call.

Hope this helps you and many others with saving data. :)

Comment
Add comment · Show 2 · 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 Waldy · Sep 15, 2013 at 11:16 AM 0
Share

I was thinking about using PlayerPrefs ins$$anonymous$$d of Unity serilizer. I'm new to PlayerPrefs and how they work so could you give a me a example, so my game AT$$anonymous$$ is all about gathering materials so when you gather wood from a tree the tree gets cut down how could i tell PlayerPrefs that it shouldn't load that tree when i next play

avatar image Bunny83 · Sep 18, 2013 at 07:49 AM 0
Share

I guess you talk about:

http://whydoidoit.com/unityserializer/

when you use third-party stuff you should be more precise what you're using. Either include a link or a better description.

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

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

Save Transform in PlayerPrefs 2 Answers

Saving Player Position Scene to Scene 0 Answers

How could I save all cloned objects in a scene, and load them back up on start? 1 Answer

Save Data Strategies 1 Answer

Save as many pickables as you want to 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