Saving and Loading
The plugin can save which foliage instances are hidden or removed, so harvested trees stay gone after the game restarts.
Enabling persistent data
In Project Settings → Game → Foliage Plugin → Saving and Loading:
| Setting | Default | Description |
|---|---|---|
| Enable Persistent Data | Off | Turns saving and loading on. |
| Auto Saving Rate | 60 | Seconds between automatic saves. Minimum 5. |
| Save Game Name | FoliageData | Name of the save slot. |
| Save File Per Level | On | Adds the level name to the save slot, for example FoliageData_Forest, so every level has its own save file. |
| Save Game Version | 1 | A save with a different version is not loaded and is overwritten on the next save. |
When data is loaded and saved
- The save is loaded on the server when the Foliage Manager is spawned, that is when the first foliage component starts in a world.
- Every Auto Saving Rate seconds, the data is saved if something changed since the last save. If nothing changed, nothing is written.
- Automatic and manual saves are written to disk on a background thread, so the game does not stall. The data is captured when the save starts.
- When the Foliage Manager ends play, for example when the game quits or travels to another map, unsaved changes are saved right away. This save waits until it is written.
- To save right away, call Save Foliage Data to Disk on the Foliage Manager. Use Get Actor of Class with FoliagePluginManager to find it. It always saves, even if nothing changed.
| Function | Description |
|---|---|
| Is Foliage Data Dirty | True if something changed since the last save. |
| Is Saving Foliage Data | True while a background save is being written. |
| Mark Foliage Data Dirty | Makes the next automatic save write the data. Server only. Available in a Custom Foliage Manager. |
| Is Saving Synchronously | True during the save made when the manager ends play. Available in a Custom Foliage Manager. |
Save Foliage Data to Disk returns true when the background save has started. The result is shown as a debug message and logged when the write is done. If a save fails, the data stays dirty and is saved again on the next automatic save.
What is saved
For every hidden or removed instance, the plugin saves which foliage component it belongs to, its instance index and its mesh, together with its original and hidden transform and when it may respawn.
The respawn time is saved as a real date and time. The Respawn Delay therefore also runs while the server is offline, and an instance whose delay has passed respawns on the first respawn check after loading. See the respawn rules.
Stumps are shown again for every loaded hidden or removed instance. Foliage Actors that were in the middle of being harvested are not saved: after loading, their instances are hidden and respawn as usual.
When a component starts, the plugin finds every saved instance again by its mesh and original location. This means saved data still works when:
- Foliage is painted or erased in the level, which changes the instance indices.
- A component is replaced by a new one, for example when PCG generates again or foliage ends up in another World Partition cell.
If no instance of the same mesh is left at that location in the component the entry belongs to, the saved entry is dropped and a warning is logged.
Instances that you moved in the editor cannot be found again. Increase Save Game Version if you move a lot of foliage in a released level.
Saves from 2.0 do not include the mesh. These entries are still found by component and instance index, and get the mesh the first time their component starts.
One save file per level
With Save File Per Level on, which is the default, every level is saved to its own slot named Save Game Name, an underscore and the level name. Saving one level never overwrites another.
If a level has no save file of its own yet, but a shared save named Save Game Name exists, for example from a version before this setting existed, the shared save is loaded once and written to the level's own slot on the next save.
Turn Save File Per Level off to let all levels share one slot.
Per-player or per-world save names
To use a different slot, for example per save file or per player, override Get Save Game Name in a Custom Foliage Manager. Your name replaces the whole slot name, so add the level name yourself if you still want one file per level. You can also override Save Foliage Data to Disk to save the data your own way.