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 thecoolracer · Feb 03, 2013 at 01:50 PM · serializationsavesave data

Save system for a Motherload-like game.

My game automatically generates the world at startup by using pre-placed gameobjects which turn themselves into something or entirely disappear so every earth chunk has the same name (like Dirt, Iron(clone) e.t.c.).

I want to make a save system which basically saves the player's money, location, inventory, fuel, health and the world(earth chunks, not shops and stuff). What is the best way to do this?

Comment
Add comment · Show 1
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 ryba · Feb 03, 2013 at 02:12 PM 0
Share

Like $$anonymous$$ecraft ? And do you prefere to save that in an database or simple text file ?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ryba · Feb 03, 2013 at 02:45 PM

Let me guess, minecraft copy ? Is your world just giant set of cubes ? For such tiled worlds saving map is quite easy, but it also depends on how big your world is, because if there is more data to save, you should do some optimization.

Minecraft world is divided to chunks and blocks. Chunk is small set of blocks. I dont remember how big is it, but it has static size, lets say 20x20x100 (100 is hipotetical height from bottom to the sky - as i said i dont remember those values).

So chunk is set of 40000 blocks. When you enter game, it loads chunks that are near player. Amount of chunks depends on player settings (render distance).

Lets say player has low distance, which means that game will load only chunks in range of 3 (manhattan distance), like that (d is distance):

alt text

Your database model should be designed like that:

 chunk_id (int, index, not null) - index of chunk that block belongs to, it must be index for fast finding
 id (int, index, not null) - index of particular block
 block_type (int, not null) - enumeration of your block type (dirt/iron/stone etc)

Make sure you wont do id columns as unique, because magic is that they should repeat.

If your chunk is 20x20x100, and contains 40000 blocks, than every block should have index from 0 to 39999. Why is that ? Because block id should relate position in chunk, not in whole world - you have chunks for that. Now when you calculate indexes of all your chunks, you do simple

 select * from blocks where chunk_id=id1 or chunk_id=id2 or chunk_id=id3

etc for each chunk.

I think you should get the idea right now. For saving other data, you can simply save it to the another simple key-value table.

That solution will be quite fast, because with such chunks you wont have big amount of indexes. If your world will be 2000x2000 wide (its really big assuming block size is like in minecraft), then you will have only 10000 chunks, and search engine will have all those blocks sorted in 10000 data clusters though there is 400000000 blocks !

If you dont want to use database, you can store each chunk in separate file, named by its index, and containing serialized set of blocks, or even csv (this will be too easy to access to player however, he will be able to edit his generated world, for example add an valuable blocks, like diamonds everywhere :P), example:

 chunkId,blockId,blockType
 1,1,4
 1,2,4
 1,3,4
 1,4,4
 2,1,4
 2,2,3
 2,3,4


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 thecoolracer · Feb 04, 2013 at 04:06 PM 0
Share

No ,the game works differently, by chunk I meant a single block.

avatar image thecoolracer · Feb 04, 2013 at 04:07 PM 0
Share

I was looking at asset store and found something interesting(free ^_^). I will try it out.

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

10 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

Related Questions

Save multiple scriptableObjects in just one binary file 2 Answers

Error when loading saved date : SerializationException: End of Stream encountered before parsing was completed. 2 Answers

im getting a serialization exception eror in my load method 0 Answers

Help with serialization 0 Answers

Save and load serialization problem 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