Skip to main content
Version: 3.5

Saving/Loading a Dungeon

Experimental

This feature is still experimental and may receive breaking changes (or being revamped) in future versions of the plugin!
But do not fear to use it as a first solution, and if you do encounter any issues with it, feel free to report them to me.
You can always implement your own save solution for the dungeon if this feature does not meet your needs.

Important Note

This feature is not an out-of-the-box solution to save/load your game.
It only handles the dungeon serialization part of your game.
You will still have to do yourself the serialization of you player character and any actors spawned at runtime.

Overview

The plugin provides blueprint nodes to your Dungeon Generator actors to serialize/deserialize the whole dungeon into a Dungeon Save Data structure. You can then hold this structure into your Save Game class to save your dungeon into a save game.

If you are using a C++ archive-based save system, you also have direct access to the functions to save the dungeon in your archive or structured archive directly.

How to save/load your dungeon

When you save/load your game, you can call the Save Dungeon and Load Dungeon nodes on a Dungeon Generator reference.

If you are using multiple generator actors at the same time, you can use the Generator ID to know which save belongs to which generator. The plugin provides also convenient nodes, Save All Dungeons and Load All Dungeons, to automatically gather generators and saving/loading them.

Here some basic examples on how to call the Save Dungeon and Load Dungeon on a unique generator actor, which is referenced in a variable of the calling blueprint class.

tip

This new blueprint representation in this wiki is an experiment.
You can navigate and interact with the nodes like in the UE Editor.
You can also copy the nodes and paste them in your editor! Feel free to share your thoughts and suggestions about it on the Discord server.

Saving actors placed in room levels

Any actor placed in a room level can be handled by the dungeon serialization.

warning

The actors must be placed in the room levels to be considered by the dungeon serialization!
The player character or any actor spawned at runtime will not be reached by the dungeon serialization system. You will have to handle them by yourself.

To be serialized, the actor (or one of its components) must implement the Room Actor Guid interface.
This interface adds 2 new functions to the actor (or component):

  • Get Guid: Must return a unique Guid in the room (the same guid can be used in multiple room instances, but each guid in the same room must be unique).
  • Should Save Actor: Must return true if you want the actor to be included in the dungeon serialization process.

The plugin provides a ready to use component called Simple Guid which provides a guid and implements this interface.
If you are already using your own guid components in your project, then you just have to implement the interface on them.

Once your actor is available for serialization within the dungeon, you can use the Save Game flag of the actor's variables to include these variables in your game save.

You can also implement the Dungeon Save interface to get access to some save/load events in your actor:

  • Pre Save Dungeon: event called only when saving a dungeon. It is called on all actors before starting the serialization of the whole dungeon.
  • Post Load Dungeon: event called only when loading a dungeon. It is called after the dungeon has finished to load.
  • Dungeon Pre Serialize: event called just before serializing the actor (saving or loading). You may use it to prepare some data before they are saved for example.
  • Dungeon Post Serialize: event called just after serializing the actor (saving or loading). You may use it to compute/update some other variables after they are loaded for example.

Saving doors generated by the dungeon

The door actors spawned by the dungeon are also handled by the dungeon serialization.
You can use the Save Game flag and the Dungeon Save interface like you would do for the actors placed in room levels (see above).
However, there is not need to implement the Room Actor Guid interface on them (unless you want to place some doors in your room levels too).

Saving other actors

As said previously, any actor you will spawn at runtime, as well as the player character and any actor not related to the dungeon (e.g. placed in the master level) are not managed by this dungeon serialization feature.

Saving the dungeon is immediate. So you can do it when you save your other actors.

Loading the dungeon is not immediate in the other hand. In fact, the dungeon data is deserialized immediately, but before applying them the dungeon first needs to unload the previous dungeon if any, and then load the room levels before applying these loaded data to the room actors.
You should spawn and deserialize your runtime actors after all that happened (e.g. in the Post Generation event).