Saving with PulseSave

Boats save themselves. APulseWaterBoat is an IPulseByteSaveable of PulseFoundation, so PulseSave (and every other save system that collects byte saveables) keeps hull health, water and leaks, sunk, upgrades, levers, place and the extras of other systems of every boat. Pulse Water does not depend on PulseSave, and no bridge is needed.

Setup

  1. Enable PulseWater and PulseSave.
  2. Let a PulseSave manager collect actors (for example with an actor collector or the world collector): it finds the boats placed in the level and the save carrier of the boats spawned at runtime.

Project Settings > Pulse > Water Boats > Saving > Save Boats (bSaveBoats, on by default) turns it off for games that save boats their own way. bSaveEnabled on a boat leaves that boat out.

Boats placed in the level and boats spawned at runtime

Boat Who saves it Save identity When the game loads
Placed in the level The boat itself Pulse.Water.Save.Boat, scope Owner: the key starts with its level and actor name, also while a player drives it (MakePlacedBoatSaveKey) The boat of the level gets the saved state
Spawned at runtime UPulseWaterBoatSaveSubsystem through a save carrier Pulse.Water.Save.Boats, scope World; each boat by its save id (GetSaveBoatId, given the first time it is saved) The boat with the same id gets the state; a missing boat is spawned again from it with the same id

A boat placed in the level that sank and was removed before the game was saved comes back from the level when the game loads: the level places it again, and the save has nothing for it. Spawned boats that are not in the save stay as they are. IsPlacedInLevel tells which kind a boat is; a boat a load spawned again counts as spawned at runtime.

Only the server (or the game without network) saves and loads; clients get the boats by replication.

What is saved

The bytes are an FPulseWaterBoatSaveData for a placed boat and an FPulseWaterBoatWorldSaveData (a list of FPulseWaterBoatSaveRecord: save id and state) for the spawned boats, both versioned (Version, written by Pulse::Serialization; bytes of a newer version are rejected). Both carry the FPulseWaterBoatSaveState of the boat (GetSaveState: boat class, transform, upgrades, hull health, water inside and where it lies, leaks, sunk, throttle, rudder, sail and extras), loaded with ApplySaveState.

Cargo, fuel and other data on the boat

Systems of the game add their data to the state of a boat as extras, one instanced struct per type:

// In OnRegister or BeginPlay of a component on the boat (boats a load spawns again have it in time)
Boat->OnSaveExtrasNative.AddUObject(this, &UMyCargoComponent::SaveCargo);  // (const APulseWaterBoat*, TArray<FInstancedStruct>&)
Boat->OnLoadExtrasNative.AddUObject(this, &UMyCargoComponent::LoadCargo);  // (APulseWaterBoat*, const TArray<FInstancedStruct>&)

GetSaveState calls OnSaveExtrasNative; ApplySaveState calls OnLoadExtrasNative on the server after the hull and the levers. Find your entry by its type (FInstancedStruct::GetPtr<FMyCargoSave>).

PulseWaterSaveBridge (obsolete)

The separate plugin PulseWaterSaveBridge saved boats through a PulseSave model (UPulseWaterBoatSaveModel, UPulseSaveWaterBoatComponent). It is obsolete: the boats save themselves now. Do not enable both, or every boat is saved twice and spawned boats come back twice.

Pulse Water is not released yet: saves written through the bridge are not carried over. Their boats are left out when such a save is loaded (placed boats keep the state of the level, spawned boats do not come back); save again once to write them in the new format.


This site uses Just the Docs, a documentation theme for Jekyll.