x


Unity types unable to be serialized

Hello,

I've written a custom inspector for GameObjects that can serialize/restore data changed at runtime (I can save the values I've changed at runtime, so they don't revert after playmode is stopped). However, most Unity types can't be serialized using the code from System.Runtime.Serialization. For example, I'd like to serialize Vector3 etc. (seems simple enough.)

Does anyone know of a work-around? Right now I can only operate on basic types; bool,string,float,int etc.

more ▼

asked Nov 10 '11 at 11:22 AM

dood gravatar image

dood
48 1 1 2

Well, there's a surprising amount of abstracted information that you can store just with primitives! If your classes derive from Unity's 'Object' class, they will hook in nicely to Unity's inbuilt serialization, but that isn't really good enough if you want to use it for player-made levels and other such custom content. I have a generic Object Loader script which I've been using to pass level setup files between my level designers- but I'm not actually sure if it'd be good for anything more than primitives and classes which only contain primitives.

Nov 10 '11 at 11:31 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

We use ISerializationSurrogate to serialize Unity objects and scripts.

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializationsurrogate.aspx

more ▼

answered Dec 14 '11 at 07:53 PM

Zeanog gravatar image

Zeanog
21

Could you be a little more specific?

Apr 12 '12 at 05:22 PM chuckrussell

yes, I would like to know more about this too!

Aug 19 '12 at 01:17 AM numberkruncher
(comments are locked)
10|3000 characters needed characters left

This is an example of usage. http://msdn.microsoft.com/en-us/library/system.runtime.serialization.surrogateselector.aspx

You just have to write a surrogate for every Unity type that you want to serialize. GameObject, Transform, etc. Our implementation for a GameObject surrogate sucked. Need to rethink that one. :)

Hope this helps

more ▼

answered Aug 21 '12 at 02:18 AM

Zeanog gravatar image

Zeanog
21

How are you registering this with the Unity serializer? The serialization mechanism (including a surrogate selector) are implemented privately within the Unity library.

Aug 21 '12 at 12:21 PM numberkruncher
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x467
x181

asked: Nov 10 '11 at 11:22 AM

Seen: 1392 times

Last Updated: Aug 21 '12 at 12:21 PM