In GridBuilding 6.0, persistence is handled by the GECS (Godot ECS) serialization pipeline. Unlike 5.0, which serialized Node trees, 6.0 serializes Component Data. This makes save files smaller, faster to load, and easier to version.
The ECS Serialization Approach
Saving a level means saving the state of entities, not the entities themselves.
- World State: Represented by a collection of entities.
- Entity State: defined by its components (
GridPositionComponent,PlaceableComponent, etc.). - Serialization:
GECSIOextracts this data into a JSON-compatible format.
Saving the World
To save the game, you query for all entities that represent persistent objects (usually those with a GridPositionComponent and PlaceableComponent) and serialize them.
| |
What gets saved?
Only components with the @export hint or those registered for serialization are saved. Runtime-only components (like PlacementPreviewComponent or HoverHighlightComponent) are naturally excluded because they aren’t part of the query or don’t hold persistent data.
Loading the World
Loading is the reverse process: Read the file, create entities, and populate components.
| |
Save File Structure
The resulting save file is clean JSON (or binary).
| |
This structure is version-agnostic (mostly). If you add a new component later, old saves just load without it. If you remove a component, the deserializer warns but continues.
History (Undo/Redo)
Because state is just data, implementing Undo/Redo is trivial. You don’t need Command patterns for every action; you just snapshot the relevant component state.
- Snapshot: Store the serialized state of the modified entity before the change.
- Undo: Deserialize that state back onto the entity.
Handling Custom Data
In 6.0, “Custom Data” is just Another Component.
If your tower has health, you don’t add a key to a dictionary; you add a HealthComponent.
| |
Test Verification
The 6.0 serialization pipeline is verified by the ECS integration suite:
Core Serialization:
res://addons/grid_placement/tests/integration/ecs/test_ecs_serialization.gd- Round Trip: Verifies that
serialize() -> save() -> load() -> deserialize()results in an identical entity. - Complex Entities: Tests entities with multiple components (Position + Transform + Metadata) to ensure all are preserved.
- Performance: Benchmarks serialization of 100+ entities to ensure it fits within frame budgets (target < 1ms).
- Round Trip: Verifies that
API Contract:
res://addons/grid_placement/tests/utils/ecs_serialization_test_utils.gd- Provides shared assertions for verifying component data integrity across tests.