• 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
4
Question by kasplask · Apr 23, 2013 at 09:34 AM · gameobjectserializationsave

Serialize a GameObject, including components

I am building a level editor for my game.

This means that I have to be able to:

  1. serialize a GameObject, all of its children and all of their components to an XML file

  2. load them back into the core game

I have read thread after thread about serialization, but I can't seem to find the right one. It's always about just saving the game. Is there a good way to completely serialize a GameObject and all of it children, top to bottom?

If you want to know why I am doing this, it's because I want my game to eventually become a moddable community project, and I don't want to require every contributor to have a Unity license. Furthermore, it facilitates the whole project structure if I can use files that are external from the core build. I generally find the package approach extremely limiting. And last, but not least, I want to enable contributors to make game content in Linux, which the Unity Editor currently does not :)

Any help on this is highly appreciated. Thank you in advance.

EDIT: I have been reading about ISerializationSurrogate, is it possible that this might be my salvation?

Comment
Add comment · Show 10
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 kasplask · Apr 23, 2013 at 09:52 AM 0
Share

I was looking at that, but it looked to me as if it was only designed around saving games. Could you give a quick example of how to serialize a gameobject and all of its children with your API? C#, UnityScript, Boo, whichever you prefer.

avatar image whydoidoit · Apr 23, 2013 at 10:13 AM 0
Share

There are examples of it in the download.

Here's the docs: http://whydoidoit.com/documentation/html/class_level_serializer.html

Looks for SaveObjectTreeToXXXX (Server/File etc).

avatar image whydoidoit · Apr 23, 2013 at 10:15 AM 0
Share

But basically you can do:

   //Save it
   byte[] data = anyGameObject.SaveObjectTree();

   //Load it back
   data.LoadObjectTree();

Note that you need a SaveGame$$anonymous$$anager component in the scene and references to other game objects will not necessarily be able to be recreated if they are outside the tree and not marked with a Unity Serializer save game script.

avatar image whydoidoit · Apr 23, 2013 at 10:19 AM 0
Share

ISerializationSurrogate won't help you - serializing Unity objects is much more complicated due to the interactions required with the system.

avatar image kasplask · Apr 23, 2013 at 10:54 AM 0
Share

That makes me very happy. Thank you so much for making this, it's goddamn genius!

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by kasplask · Apr 25, 2013 at 07:18 AM

I was very inspired by the Unity Serializer by whydoidoit, but I actually ended up writing my own serializer based on the JSONObject class. The Unity Serializer is very good for serializing everything, but if you are just moving around some prefabs, I'd recommend rolling your own.

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 whydoidoit · Apr 25, 2013 at 08:00 AM 0
Share

Good stuff :)

avatar image
2

Answer by Voxel-Busters · Aug 08, 2015 at 03:04 AM

You can directly serialize GameObject using our plugin Runtime Serialization for Unity. Its not just another serialization plugin which works only on custom c# objects. But what makes it special is its capablity to serialize 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
avatar image
1

Answer by whydoidoit · Apr 23, 2013 at 09:35 AM

You can use Unity Serializer to do that. It supports individual objects and whole games - but it only support compressed binary and JSON formats.

Comment
Add comment · Show 3 · 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 Psyco92 · Aug 27, 2014 at 02:27 PM 0
Share

I was being a banana and didnt rtfm properly... I had for gotten to LevelSerializer.AddPrefabPath() when using my resources... Brilliant package !!! thank you

avatar image sami1592 · Aug 03, 2015 at 03:12 AM 0
Share

as far as i know the unity serializer does not work in windows phone, any idea about that?

avatar image huulong · Nov 07, 2016 at 09:55 PM 0
Share

Continuation of Unity Serializer on https://gitgud.io/TheSniperFan/unityserializer-ng, although discontinued too. Support up to Unity 5.4.

avatar image
1

Answer by MidnightStudiosInc · Jul 01, 2015 at 03:05 PM

GameObject Serializer Pro can serialize entire GameObjects, their children, and their components.

Currently the supported types list supports only some of the most common types like meshes, transforms, etc, but I can add more types as there is demand for them.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

How to save/load references to components and prefabs 1 Answer

Serialize Data - After Update 1 Answer

Problem whith save system,Problem whith save code 0 Answers

Don't Load Collected items 1 Answer

Save EditorWindow to disk 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