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 coastwise · Nov 02, 2012 at 01:54 PM · editorinspectorserializationscriptableobjectcustom-inspector

How should I serialize data that is also editable in the Inspector?

I have successfully achieved both of the requirements in isolation:

  1. Using a `BinaryFormatter` to serialize an arbitrary object, converting it to Base64, and storing it in the cloud. I can later download, convert to byte array, deserialize and cast to my type.

  2. Implementing a custom type that extends `ScriptableObject` that is fully editable in custom Inspector. Values are saved with the Scene, and generally working great. (Thanks to the Serialization Best Practices Megapost)

My problem is that I would like to take an instance of this `Class` that extends `ScriptableObject` and pass it through my serializer to store online. However I get the error that `ScriptableObject` is not marked as serializable.

 SerializationException: Type UnityEngine.ScriptableObject in assembly UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null is not marked as serializable.

Has anyone come up with a method / pattern to achieve this functionality? Should I forgo the Unity serialization entirely and use my mechanism directly from the Editor? It seems like a very ugly solution to me, but its the only solution I can think of at the moment.

Thanks in advance

Comment
Add comment · Show 2
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 originalNarf · Dec 20, 2012 at 12:04 AM 0
Share

Can you post the code you're using? And the full error?

avatar image MortenK84 · Mar 31, 2014 at 06:36 PM 0
Share

Did you ever find a solution to this?

2 Replies

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

Answer by vexe · Apr 21, 2014 at 09:41 AM

Edit: See VFW for a better/advanced serialization system


The thing is, you can't use BinaryFormatter for UnityEngine.Objects because they're not mocked with Serializable which is required by BinaryFormatter. I am also seeking optimal solutions for this - The problem is, even if say, you use an annotation-free serializer (like Migrant for example) you're not guaranteed to get the object back safely upon deserialization - Because, for example let's talk about Components, why doesn't unity allow us to create them with the new operator but only with AddComponent? obviously, because Unity does some prepping/internal home cooking to build the component, things that not any serializer could figure out on its own.

The best way I found to serialize UnityEngine.Objects is to leave their serialization to unity itself, don't bother.

If you want to serialize them to a readable format upload them to some server and download later, you could check out @whydoidoit's awesome Unity Serializer.

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 frarees · Apr 01, 2014 at 08:25 AM

A custom non-generic class marked with [System.Serializable] will be serialized by Unity, and you can use a BinaryFormatter for runtime serialization.

E.g.

Player.cs

 [System.Serializable]
 public class Player {
     public string name;
     public int level;
     [SerializeField]
     int hp;
 }

...

 public class MyScript : MonoBehaviour {
     public Player player;
 }
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 MortenK84 · Apr 01, 2014 at 06:10 PM 0
Share

OP's problem seem to be the same as $$anonymous$$e: An object derived from ScriptableObject which is saved as an asset and thereby editable in the inspector, will not serialize even though it is marked as [Serializable]. Attempting to serialize the object gives the error that OP describes in his post.

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

13 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

Related Questions

[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer

Why doesn't my ScriptableObject save using a custom EditorWindow? 3 Answers

How to make a serialized editor only field 2 Answers

Select a readonly value from dropdown using PropertyDrawers 0 Answers

Custom Inspector; adding to list not getting saved 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