Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Sidadi657 · Dec 05, 2020 at 09:06 AM · save scene

Hello,I am trying to build a save mechanism for a building game in unity in which the player can save a 3d scene.should i use a database or what?

Hello everyone i am building a building game in unity in which the player can build a city i want the player to be able to save the scene that he has build so he can go back to it when he plays next time,how would i be able to build the saving mechanism.Should I use a database like mongodb to save the position,rotation,scale,etc for the objects that the player has made and placed(but i think that would be too lengthy) or should i do something else.Pls Help

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 sacredgeometry · Dec 05, 2020 at 02:01 PM 0
Share

Tunials answer is pretty correct and sufficient but I would add to only use a database if your game is very data centric and will need to regularly store and access lot of data in a bunch of ways.

Just persisting basic game (i.e a few properties on a few different objects) state is probably not a valid use case for a full featured database.

If you are making something like an RPG then I would definitely say its a healthy consideration.

If it does need one then there are lots of options available and different types depending on the need but maybe the easiest to implement and integrate would be something like a SQLite database. $$anonymous$$ongo could also be a good candidate but I would suggest spending some time with document style databases before investing heavily in that direction over a relational style one because it can be a lot easier to tie yourself in knots.

avatar image sacredgeometry · Dec 05, 2020 at 02:04 PM 0
Share

Oh wait you said its a building game. Yeah that potentially could be useful

avatar image Sidadi657 · Dec 06, 2020 at 09:28 AM 1
Share

Thanks @sacredgeometry I was also thinking of using a database. I think a mongodb server would be best for me as I have used mongodb earlier also.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tuinal · Dec 05, 2020 at 12:23 PM

This for me is one of the best tutorials for it.

https://www.raywenderlich.com/418-how-to-save-and-load-a-game-in-unity

The 'proper' way to save in Unity is to serialise every element of data that needs to be saved, and write it to disk. You can in theory use a text file as above, or PlayerPrefs for quick prototypes, but PlayerPrefs is designed (as the class name suggests) to hold a small amount of information on preferred settings rather than a whole savegame.

You basically need to distil the core information into classes you can serialise, which means they need to be serialisable. This means breaking the data back down towards basic types (or serialisable ones like Vector3). Using GetComponentsOfType can be a big time-saver (e.g. you can get all rigidbodies then iterate through them saving position/rotation).

Saving (properly) in general is one of the trickier things to do in Unity and it's best if you make it a priority when starting development, especially if 'save anytime' is a required feature. It's particularly complicated if you're adding/instantiating a lot of things at runtime that need to persist, since you need to handle tracking them and respawning them in the correct state when the game loads. This is because you need to consider when adding any new variable 'will I need to save this?' and update the savegame code accordingly.

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 Sidadi657 · Dec 06, 2020 at 09:30 AM 0
Share

Thank you @tuinal,but I want to ask which would be better, a local saving method or a database.

avatar image
0

Answer by Llama_w_2Ls · Dec 05, 2020 at 10:10 AM

You could write to a text file containing the position, type, and transform of each block in the building game and then extract that data every time you reload the scene by reading that text file. I've created text files thousands of lines long (when converting STL files to meshes) containing data such as this and it's read almost instantly if you use the right approach.


Warning: This isn't really the way to go if you want secure, safe data saving as the files aren't encrypted, and if the files are deleted or corrupted, all your data could be lost.

If you want to use a database, that seems like a more logical, efficient, industrial approach rather than the easy way out of writing and reading a text file. It's your choice @Sidadi657

Comment
Add comment · Show 5 · 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 Sidadi657 · Dec 06, 2020 at 11:06 AM 0
Share

Thanks for your reply

avatar image Llama_w_2Ls Sidadi657 · Dec 06, 2020 at 03:06 PM 0
Share

Writing to databases will always be quicker and take up less space, as thousands of man-years have gone into perfecting the transmission and storage of data in databases. Choose a database type that would be best-suited for you. For example, if you're worried about the speed of sorting, retrieving and writing to databases, try a fast database. If you're worried about storage, try an efficient database. etc.

avatar image Sidadi657 · Dec 06, 2020 at 05:50 PM 0
Share

OK thanks. I have started using mogodb in my game :-)

avatar image TheWhispers · Dec 07, 2020 at 08:30 PM 0
Share

Why would a game save need encrypted?

avatar image Llama_w_2Ls TheWhispers · Dec 25, 2020 at 10:24 AM 0
Share

If the data was easily readable, the player could modify it without penalty @TheWhispers

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

140 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 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 avatar image avatar image avatar image avatar image

Related Questions

Unity Scene Loading Crash 0 Answers

Loading the previous game level after closing the game -1 Answers

How to save gameobject created at runtime ? 1 Answer

Keeping variables through scenes 1 Answer

"Machine Identification is Invalid for Current License"? 9 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