• 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 /
  • Help Room /
avatar image
Question by ChesStrategy · Dec 19, 2015 at 08:08 AM · unity 5serializationsavingstateserializable

Understanding the need of serialization

Hi all,

I'm new to Unity; so far it seems like a good solution to my project; however in preparation, I've heard various comments on limitations due to serialization. I would just like to confirm some of my understanding... is the only purpose of designing your classes to be serializable by Unity and/or making it serializable by deriving from ScriptableObject to allow game state and changes to persist between play mode and edit mode? Isn't this issue completely avoided if we write a custom class to save game state into a flat file like XML or JSON? Or is there something crucial/core to Unity that requires me to understand serialization?

I understand serialization may be important to learn; but its importance is only based on whether you need to persist game state between editor and play modes during development? When the game is actually released; a different form of saving game state will need to be used anyways correct? Or is it just really late at the moment and I'm misunderstanding all of this?

Regards, A new Unity user

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Xarbrough · Dec 19, 2015 at 05:39 PM

Hm, there's a couple of pretty big concepts to explain, but here are just some breadcrumbs:

Unity serializes fields in your MonoBehaviour components to show them in the inspector. Nice for setting designer variables. ScriptableObject does basically the same thing, but it doesn't need to be a component on a scene object. It can be a simple data asset, which is just a super great way of storing binary data in Unity and using custom editors and editor features to edit that data instead of plain formats like text. ScriptableObject also work in the build, but they are probably intended for data like setting up player items and then using that data as part of an inventory system in the game. Saving data in game is often done as binary files, xml, json or other text formats.

Introduction to Scriptable Objects

Comment

People who like this

0 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 ChesStrategy · Dec 21, 2015 at 01:29 PM 0
Share

So if I don't structure my code to use unity serialization, and store state in say... XML, what features in unity do I lose? That's my concise question... or is using unity serialization a must?

avatar image Xarbrough ChesStrategy · Dec 21, 2015 at 04:05 PM 0
Share

First, you lose the ability to edit script variables in the inspector, if you make them private and don't mark them with the SerializeField attribute, or if your script doesn't derive from MonoBehaviour. But Unity can still use regular custom classes, when they are marked as System.Serializable and things like that, but unity serialization is all about editor features, so that's what you're losing. If you don't need any of those Unity editor features, you don't have to think about serialization, then just think about how to save and persist data in your games, that's a different topic.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Serializing name of the current level 1 Answer

Looking for a more efficient method of saving for mobile game. 0 Answers

How to Serialize or Save a List of GameObjects 1 Answer

.data serialize and deserialize work in editor but not in build 1 Answer

How to save many instantiated objects position/rotation at runtime??? 2 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