Unity Xml Serialization Unity

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

Easy Serializer for Unity. This project aims to make object serialization in Unity as simple as possible while supporting all platforms. Platform Support. PC/Mac/Linux standalones, iOS, Android. Preparing the object for serialization. First, you need to make sure that the class you want to serialize adheres to one of the two following. Saving Data in Unity 3D (Serialization for Beginners). If yes, then save to a file using some serialization method (binary, JSON, XML, etc). Otherwise it is likely only a variable that needs to be known throughout this session and can simply be stored in a static variable (Session Data). But they’re perfect for storing things like mute. Introduction to serialization using the JSON format to save and load player data. We cover the basic concepts of serialization as well as the practical aspects. Choose a format / structure for.

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?

Active5 years, 1 month ago
$begingroup$

I'm trying to serialize a GameObject (with children and textures) using the binary serialization for C#.

It works with many data types but not with GameObject. In the docs it says should be serializable (http://docs.unity3d.com/ScriptReference/SerializeField.html):

Serializable types are: - All classes inheriting from UnityEngine.Object, for example GameObject ....

I've read suggestions of using the asset of UnitySerialization, but that is overkill for me, I just need to store a GameObject on my scene (that will be generated by many users) and load them all in another scene.

This is the code (I'm following this tutorial: http://www.youtube.com/watch?v=J6FfcJpbPXE&feature=player_embedded)

Check the Save/Load functions. I'm just trying to store the 'drawing' (GamObject), save it and load it. That's all! Is very simple. With other data types it works. But not with GameObject.

Unity C# Xml

This is the (execution) error:

SerializationException: Type UnityEngine.GameObject is not marked as Serializable.

Unity
KaniKani
$endgroup$

1 Answer

$begingroup$

SerializationException: Type UnityEngine.GameObject is not marked as Serializable.

That means UnityEngine.GameObject is not marked with the Serializable attribute, which is a requirement (just because Unity says a type is serializable doesn't mean it's serializable with all serialization engines; in this case, it probably means that the type is serializable with Unity's engine, not the one that is part of the .NET BCL).

You can either use Unity's serialization mechanism, or you can try your hand at implementing an ISerializableSurrogate object for the Unity game object (this is likely to be tricky, and more effort than just using Unity's serialization).

JoshJosh
94.4k17 gold badges212 silver badges330 bronze badges

Unity Xml Serialization

$endgroup$

Unity Xml Serialization Unity Point

Not the answer you're looking for? Browse other questions tagged c#unityserialization or ask your own question.