Menu
Lumberyard
Developer Guide (Version 1.12)

Serialization

The Entity system is currently on a path to deprecation in favor of the Lumberyard Component Entity System.

All entities created or prepared through the entity pool system are serialized by the system for game save/load. For this reason, do not serialize those entities marked as coming from the pool (IEntity:IsFromPool) in your normal serialization. This is handled in Lumberyard's default implementation for saving and loading the game state.

The entity pool system is serialized from the Entity system's implementation of the Serialize function.

Saving Entity Pools

The following process occurs when the game state is being saved:

  1. All active entity containers in all entity pools are updated. This results in CEntityPoolManager::UpdatePoolBookmark being called for each active entity container. As long as the entity does not have the ENTITY_FLAG_NO_SAVE flag set on it, the bookmark is serialized as follows:

    1. Serialize Helper writes to the bookmark's pLastState (an ISerializedObject), which contains the serialized state of the entity.

    2. The callback CEntityPoolManager::OnBookmarkEntitySerialize runs through the serialization process on the entity. This ensures that the general information, properties and all entity proxies are serialized using their overloaded Serialize() implementation.

    3. Any listeners subscribed to the OnBookmarkEntitySerialize callback are able to write data into the bookmark at this time. This is used to also bookmark AI objects along with the entity.

  2. All entity pool bookmarks are saved, including the static entity and dynamic entity usage counts.

  3. If any prepare requests are currently queued, the prepare request queue is saved.

Loading Entity Pools

The following process occurs when the game state is being loaded:

  1. The saved entity pool bookmarks are read in. If the bookmark is marked as containing a dynamic entity, it is read to ensure it exists. Each bookmark's pLastState is read in and updated.

  2. If the entity pool bookmark contains an entity that was active at the time the game was saved, the entity is created/prepared from the pool once more.

    1. While the entity is being created/prepared, it will load its internal state using the pLastState at its final step, because the object contains information at this point.

    2. This will also call the OnBookmarkEntitySerialize listener callback, allowing other systems to read data from the bookmark.