Saving and Loading

From Eco - English Wiki
Revision as of 17:38, 4 July 2021 by Redwyre (talk | contribs) (Created page with "{{ModdingOutdated}} == Modding Tutorial: Save/Load == === Steps === To do serialization, all that is needed is: 1. Add `[Serialized]` attribute to the class that will be...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:ModdingOutdated

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!