ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.
From April 26 to May 12, errors may occur in the Wiki, as we will be carrying out a major update to the information processing modules.

Saving and Loading

From Eco - English Wiki
Warning: This content is outdated.

Modding Tutorial: Save/Load[edit | edit source]

Steps[edit | edit source]

To do serialization, all that is needed is:

1. Add `[Serialized]` attribute to the class that will be serialized:

	    [Serialized]  
	    public class Door : WorldObject

2. Any primitive/simple members you want serialized, add the `[Serialized]` attribute:

	    [Serialized]  
	    private Vector3i zoneStart;

3. Custom classes (classes that you write that don't inherit a base class) must also have a default, e.g. parameter-less, constructor. Feel free to make this private. Beware that this constructor will be called *before* loading, so don't do anything that you don't want done on load.


If the member is a class, the serializer will recurse into it, so make sure to do these steps for custom classes you write.

References[edit | edit source]

References to classes will be serialized in-place, meaning that if two classes reference the same instance of something, that something will be serialized twice. This leads to two copies of the same object, which is likely not what you want. Make sure when working with your own custom classes to remember that this is the case.

For our internal classes, we provide a 'Handle' classes that makes serialization a little easier.

Here is a list of current handles and their usage:

    PlayerHandle playerHandle = new PlayerHandle(somePlayer);
    playerHandle.Player.Foo();

    WorldObjectHandle<Door> door = new WorldObjectHandle<Door>(someDoor);
    door.Object.Foo();

Some handles also provide references to related types, such as PlayerHandle.User

By adding `[Serialized]` to any of these types, they will be correctly serialized. Make sure not to serialize Eco's internal classes raw!