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
1
Question by william0220 · Feb 08, 2012 at 10:15 AM · gameobjectscenesavexml

Saving and loading a GameObject built in-game

Hi, I'm trying to make a game with a gameplay style similar to Kerbal Space Program, where you first build your vehicle in game and then drive it in a second scene. However I'm not too sure on how to save the contructed vehicle and also load the it into the second scene.

Currently I've got 2 scenes : Construct and Main. Constuct is loaded first and is where you build the vehicle. It basically consists of a bunch of GUI buttons that instantiate a component prefab that can be added to a vehicle base which is also a prefab. The components are added to the base as childs. Once the vehicle is finished a start button loads the Main game scene where you can pilot it against enemies and such. Once you finish an objective or your vehicle gets destroyed you return to the Contruct scene where you can modify or add more components and so on.

A quick example of a vehicle:

alt text

The problem I have now is how to load the vechile into the Main game scene, and also saving the vehicle so I can load it again.

So far I've tried putting DontDestroyOnLoad on the vechile but any damage taken is passed back to the first scene, also if the whole ship is destoryed its lost forever unless I create a duplicate first but that just feels wrong. Also it doesn't address the saving issue.

I'm thinking that there must be some way of saving the created vehicle gameobject. It would pretty much have to create a seperate text file or XML file for saving so I've looked at other similar questions about saving with PlayerPrefs or XML but they all deal with saving and passing parameters such as positions rather than the actual gameobject itself. Currently I'm thinking the game would work by instantiating the saved vehicle on awake of the Main scene but I'm just not sure how to get the required info such as the different prefabs on the ship.

Considering that Kerbal Space Program is also made using Unity and it has pretty much the exact gameplay style that I'm aiming for I know it can be done, but just don't know yet since I'm still relatively new to Unity. If anyone knows how to implement this your help would be greatly appreciated. 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tingham · Feb 08, 2012 at 01:26 PM

You can serialize whatever you want to something like JSON or XML (using any of the freely available libraries you will find from a basic google search.) You would create a database that exists separately from the unity save game state such that you can recall from it any of the information you store there. There are a couple of efforts at full serialization using introspection that might be worth your time as well.

http://answers.unity3d.com/questions/8044/what-is-the-easiest-json-library-to-integrate-with.html

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 by0log1c · Feb 08, 2012 at 01:32 PM 0
Share

Transform/GameObject class were made non-serializable hence cannot be serialized directly. The OP would have to serialize pertinent data to reconstruct the object later but cannot serialize the object itself.

avatar image tingham · Feb 08, 2012 at 01:46 PM 0
Share

You're right and I should clarify my "whatever you want" to "the pertinent information." Let's see how the answer fairs when the poster gets back.

avatar image william0220 · Feb 09, 2012 at 09:47 AM 0
Share

Thanks for the reply. I'm still looking into this though since I'm only working on this casually. Never the less I'll still check out JSON considering it won't hurt to know more. Anyway I'm somewhat suprised that this saving feature is so complicated to implement.

avatar image Lunprod · Jul 05, 2015 at 10:55 PM 0
Share

Did you ever figure how to do it?

avatar image Cherno · Aug 09, 2015 at 07:52 AM 0
Share

You can take a look at SerializerHelper, a ffree asset written by me that lets you save and load whole gameobjects, and has lots of documentation throughout the scripts so it's easy to understand and modify/write your own serialization system.

avatar image
0

Answer by Voxel-Busters · Aug 09, 2015 at 05:04 AM

Try Runtime Serialization for Unity for easy serialization of custom c# objects as well as Unity Objects like GameObject, MonoBehaviours, Textures, Prefabs etc. As a matter of fact, you can even use it for Scene Serialization. For more info about supported list, please check this link.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to save all scene? 1 Answer

Assets/Save Game Script.cs(87,45): error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `=' 1 Answer

Using empty gameobjects as "folders" in scene hierarchy panel 1 Answer

Saving for a Level Editor 1 Answer

How to reset a scene from collision with a GameObject? 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