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
10
Question by unityplease · May 06, 2015 at 03:17 PM · serializationsaveload

Best way to save and load all objects and their parameters in a scene.

I'm trying to read up on serializable. But I was wondering if unity has a simple way to save every gameobject/ including all those instantiated and their parameters/scripts with references to a file. And how to load that scene state?

Is there an easy way to do it without rewriting all the code so that every game object that gets instantiated gets put into a list of gameobjects that is serialized?

Would there be a simple way to collect all gameobjects currently in a scene and save/load them? Does anyone have a clear tutorial on this?

Comment
Add comment · Show 9
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 Cherno · May 06, 2015 at 03:34 PM 0
Share

Hoo boy. No, Unity doesnt have a (built-in) feature like that. There are commercial assets on the asset store that can do what you want, however in the end I scripted my own taking some $$anonymous$$or inspiration from Unity Serializer. It was a long, arduous piece of work but I'm pretty happy with it. If I get the neccessary motivation and time in the next few days I might post a lengthy explaination of the whole thing. Until then, I can only dangle a carrot in front of your face, so to speak ;) Oh, and after extensive research I can honestly say that there are no all-encompassing tutorials for serializing whole scenes, and there is virtually zero recent information on how to deal with $$anonymous$$onoBehaviour scripts in that regard.

avatar image unityplease · May 06, 2015 at 03:57 PM 0
Share

Oh shi- thanks for that honest answer. I'm still keeping my fingers crossed that someone has done a simple (collect all gameobjects - serialize them - save them) script I can drag and drop onto a button. Here's hoping.

I am also looking for a decent file browser/chooser written to use the new unity 4.6+ UI system. However I can't find a pre-written one. $$anonymous$$ight follow this up with a new question to that effect.

avatar image khos85 unityplease · Dec 12, 2015 at 04:44 PM 0
Share

Hi, I would like to ask if you would be willing to give advise on how you managed to serialise a scene, I'm trying something similar, but not sure how that could be done.

avatar image Cherno · May 06, 2015 at 04:09 PM 0
Share

Unity Serializer theoretically can do collect all gameobject, serialize them, and save them. However, support has sadly dried up for years now, and it is fairly complex code with critical errors that never got corrected, but an excellent starting point for scripting one's own serialization system. There's no other free asset that does that, at least that what my research has brought up (or didn't bringup, really). The reason saving & loading scenes in Unity is difficult is because it requires insight into advanced thematics like Reflection, per-field-writing, and ISerializationSurrogates for all the Unity-specific things that are serializable for Unity, but not serializable in regards to the respective .NET functions.

$$anonymous$$aybe I should reword my statement about the difficulty: It's not that hard to code a working serialization system, but one that does most of the work for you, without the user having to create all sorts of container classes and variable associations him or herself is hard. Hmm.. this all sounds very technobabble so just stay tuned and I'll post how I do things.

avatar image unityplease · Jun 25, 2015 at 12:24 PM 0
Share

Any progress with this? I have made a very complex game with lots of characters walking around each instantiated with their own individually randomly chosen materials.

I'd like to save their script properties their locations, etc. But for sometime that seems so essential to game design there is nothing available only tutorials on how to save individual serialized simple types.

I tried creating a serializable data class with gameobject lists inside it. But it wouldnt' serialize.

avatar image shdes161 unityplease · Dec 12, 2015 at 10:50 PM 0
Share

I use the binaryformatter. https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading

That video tutorial should give you the basic idea from there. I use that along with my own component (script) on the objects i save so that I know what they are (for an inventory system I designed).

Hope that helps a bit

avatar image Cherno unityplease · Dec 13, 2015 at 10:28 AM 2
Share

I released an asset a couple of months ago, sorry I didn't bookmark this thread, otherwise I would have updated it.

Here is the link:

SerializeHelper

avatar image Ginxx009 Cherno · Jan 28, 2017 at 11:01 AM 0
Share

can i ask you something sir @Cherno . I have a problem with the SerializeHelper . When i grab the canvas and make it a prefab my script doesn't follow it . i mean in my canvas i have a UI Button and it has an OnClick() code . But when i make my canvas a prefab the code disappear . help please

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by xAdamQ · Aug 02, 2017 at 03:41 PM

If you want to save data use PlayerPrefs class.

You can also select all GameObjects in The scene and copy them to current or another scene.

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

Answer by J_LTD · Aug 02, 2017 at 04:30 PM

No, unity does not have a simple way to do this, you will have to use the unity serializer or code your own.

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

Answer by getloader · Nov 06, 2018 at 09:23 AM

This is disappointing. You can save scenes in the editor all they had to do is allow scene state to be saved at runtime. I don't know maybe it's not simple. Other game engines like renpy or rpg maker comes with save system out of the box but I guess argument can be made that unity is not limited to one type of game like the other engines. PlayerPref is just a no no for saving general game data other than storing game settings (audio, graphics , controls etc). Serialization seems to be the only way. But if your game is more than a few classes big this gets tedious. Maybe I am doing something wrong hope experts will show how they do it. Not only is it lot of work if you have lots of things to save but also if you have something to add later it is a lot of extra work.

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

27 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

Related Questions

Bool array to binaryformatter method 1 Answer

Save Game loading Deserialization from disk 1 Answer

Serializing Properties (JSON saving and loading system) 2 Answers

"Unbroken Reference" problem when using a custom Editor to Save/Load a ScriptableObject Asset 0 Answers

Deserializing data with XML Serializer 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