> For the complete documentation index, see [llms.txt](https://wesyc.gitbook.io/voronoimapmaker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wesyc.gitbook.io/voronoimapmaker/how-to/write-your-own-preset.md).

# Creating Custom Presets

Presets are C++ classes, so you can write your own. In this guide, you'll copy the **Starter 2 km** preset into your project and change one of its settings. Then you'll build a map from your copy.

**Before You Begin**

* A C++ project, with a game module under `Source`. A Blueprint project gets one when you add a C++ class with **Tools** > **New C++ Class**.
* Visual Studio or Rider, set up to build Unreal Engine projects.
* The Voronoi Map Maker plugin enabled in the project: see [Installing the Plugin](/voronoimapmaker/get-started/installation.md).

Wherever you see `MyGame` below, put in the name of your game module's folder under `Source`.

## 1. Adding VoronoiMap to Your Build File

Your preset will be a subclass of `UVMMPreset`, which lives in Voronoi Map Maker's `VoronoiMap` module. To compile it, your module has to depend on that module.

Open `Source/MyGame/MyGame.Build.cs` and add `"VoronoiMap"` to the modules in `PublicDependencyModuleNames`:

```csharp
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "VoronoiMap" });
```

## 2. Copying Starter 2 km into Your Module

The shipped presets come with their source code, in the plugin's folder. If you installed from Fab, it's under `Engine/Plugins/Marketplace` in your engine. Fab may give the folder a coded name, so look for the one that holds `VoronoiMapMaker.uplugin`.

1. From the plugin's folder, copy `Source/VoronoiMap/Public/Presets/VMMPreset_Starter2km.h` and `Source/VoronoiMap/Private/Presets/VMMPreset_Starter2km.cpp` into `Source/MyGame`, beside `MyGame.Build.cs`.
2. Rename the copied header `MyIslandPreset.h`, and the copied source file `MyIslandPreset.cpp`.

## 3. Renaming the Class

Voronoi Map Maker's own Starter 2 km is still loaded next to your copy, and Unreal won't allow two classes or enums with the same name. So in both files, swap each name on the left for the one on the right:

| Replace                  | With             | What it is                                                            |
| ------------------------ | ---------------- | --------------------------------------------------------------------- |
| `VMMPreset_Starter2km`   | `MyIslandPreset` | The class, which becomes `UMyIslandPreset`, and its generated header. |
| `EVMMStarterIslandShape` | `EMyIslandShape` | The enum of the **Island shape** row.                                 |
| `VMMStarterPreset`       | `MyIsland`       | The namespace that holds the preset's numbers.                        |
| `VORONOIMAP_API`         | `MYGAME_API`     | Your module's export macro: its name in capitals, then `_API`.        |
| `"VoronoiMap"`           | `"MyGame"`       | The namespace of the preset's name and description, for localization. |

Then, at the top of `MyIslandPreset.cpp`, change the first `#include` to `#include "MyIslandPreset.h"`, since the header is now beside it.

## 4. Naming the Preset

The constructor in `MyIslandPreset.cpp` sets the name and description the **Preset** picker shows. Change its first two lines to anything you want. We will be straightforward here:

```cpp
PresetName = LOCTEXT("MyIslandName", "My island 2 km");
Description = LOCTEXT("MyIslandDescription", "One island, mine.");
```

Leave `SizeMetres` as it is. Each preset is made for one map size, and this one is 2017 m.

## 5. Changing a Default Value

Every `UPROPERTY` in `MyIslandPreset.h` becomes a setting in Map Settings:

| In the code                   | In Map Settings  |
| ----------------------------- | ---------------- |
| `DisplayName`                 | The label        |
| The `/** */` comment above it | The tooltip      |
| `ClampMin` and `ClampMax`     | The slider range |
| The value after `=`           | The default      |

Find the peak height:

```cpp
/** Height of the island's middle, before ground noise is added. */
UPROPERTY(EditAnywhere, Category = "Land", meta = (DisplayName = "Peak height (m)", ClampMin = "20.0", ClampMax = "300.0", Delta = "5.0"))
float PeakHeight = 150.f;
```

Change `150.f` to `220.f`. `Generate` reads the row as `PeakHeight`: your default until the user edits the row, then the number they set.

## 6. Compiling and Creating a Voronoi Map

1. Close the editor, and build your project, so the editor loads the new class when it opens.
2. Open the project. In the **Content Browser**, click **Add** > **Voronoi Map Maker** > **Voronoi Map**. **My island 2 km** is in the **Preset** list.

   ![](https://3805039795-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGZSrmXCQuRmtnN4PwZD2%2Fuploads%2Fgit-blob-d2da539e0faed1af8e1359a19378fca4f2b266b5%2Fwrite-your-own-preset-picker-v1_0.png?alt=media)
3. Pick **My island 2 km** and click **Create**.

## 7. Changing a Builder Step

`Generate` builds the map. Each `Builder.Add...` call adds a step, and each `Builder.Set...` call sets a value the steps read. Near the top of `MyIslandPreset.cpp`, find the river widths:

```cpp
constexpr float RiverHeadWidthMetres = 60.f;
constexpr float RiverMouthWidthMetres = 120.f;
```

Each river runs from inland out past the coast, and `Builder.AddChannel` places it with these two widths, narrow at its head and wider at its mouth. Change `RiverMouthWidthMetres` to `200.f`, then press **Ctrl+Alt+F11** in the editor to compile it with Live Coding. Your map picks up the new code the next time it rebuilds, so drag any setting and the rivers get wider.

If your code needs random numbers, use the `Random` stream in `Generate`, or go through the builder. That way the same seed always gives the same map. `FMath::Rand` would give a different map on every rebuild.

## Where to Read More

The plugin's headers explain each part of a preset. They're under `Source/VoronoiMap/Public` in the plugin's folder from step 2.

| File                 | What it explains                                                                                   |
| -------------------- | -------------------------------------------------------------------------------------------------- |
| `VMMPreset.h`        | The preset class, what makes a property a row, and `OnLand`, which adds more once the land is cut. |
| `VMMPresetBuilder.h` | Every call `Generate` and `OnLand` can make on the builder.                                        |
| `VMMRecipe.h`        | The fields of each step you hand the builder.                                                      |
| `VMMPresetHelpers.h` | The helpers the shipped presets share.                                                             |

For worked examples, read the shipped presets in `Source/VoronoiMap/Private/Presets`.

## Troubleshooting

* **Create is greyed out in the dialog.** Something in your class isn't allowed. Hover over **Preset** and the tooltip may tell you. It could be a missing `SizeMetres` or one that isn't 2017 or 4033, a property type that can't be a setting, a `Category` other than `Land`, `Climate`, `POI` or `Roads`, or two settings with the same label.
* **There's a red line under the Preset picker.** Your `Generate` failed, so the map still shows the last one it made. Open the **Message Log** to see why. It shows the builder call that was refused, or the reason your preset passed to `Builder.Fail`.
* **The map keeps the old layout after a Live Coding compile.** The map only runs your preset again when it rebuilds. Drag any setting, or change the seed and change it back.
* **A map made from your preset shows a shipped preset instead.** Voronoi Map Maker can't find your class, because its module isn't loaded or you renamed it.

## Next

* [Creating Stamps from Custom Heightmaps](/voronoimapmaker/how-to/make-a-stamp.md)
