Skip to main content

Structures

The Structures feature allows you to place hand-made structures inside procedurally generated levels. For example, the level below contains a bunch of hand-made chests, a pier with a fire, and a cave.

Showcase

Getting started

Creating your first structure

Structures build on top of the Level editor, so you need to be familiar with it. Go to "Create -> Frigga -> Structure" to create a new structure. This creates a new level editor prefab for you.

Assign the theme that you want to use in the level generator, initialize the output, and create the structure. For this example, I created a structure containing a treasure chest.

Chest

Notice that the structure contains 2 fixed tiles and bunch of other tiles. The fixed tiles will always look exactly the same when placed in a level because the theme engine is not allowed to touch them. However, the other tiles might look different. For example, the tile that contains the tree might now have a tree there when placed in a level. The only guarantee is that there will be a ground tile there.

You can use these non-fixed tiles as a buffer zone around the fixed tiles that guarantees what kinds of int grid tiles will surround the structure.

Int grid tiles on the border

Later, when the structure is being placed in the level, the placement algorithm looks at the int grid tiles that are on the border of the structure to determine a good position. For example, in the chest structure from the previous section, all the border int grid tiles are set to "Ground". You can see that if you click the "Toggle Int Grid" button. This means that when the structure is placed, the algorithm will look for a position that contains ground tiles in the same shape as the border of the structure.

info

Even if you have fixed tiles on the border of a structure, you should still place int grid tiles underneath them to guide the placement algorithm.

Structure border

Configuring the generator

Head inside the Walker generator component, find the "Structures" section and click the plus button in the list.

Empty structure

You can see a bunch of properties that you can configure:

  • Name: The name of the structure, used for debugging purposes.
  • Count: Whether to spawn multiple structure or just one.
  • Probability: Probability of spawning the structure if Count set to Single.
  • Min Count and Max Count: If Count is set to Multiple, these properties define the minimum and maximum number of structures to spawn.
  • Min Accuracy: Configures how nicely the structure must fit in the level. The generator looks for a position where the int grid tiles on the border of a structure match the int grid tiles inside the level. A 100% precise placement is not always possible, so this property configures the percentage of border tiles that match. The placement algorithm will try to find the best matching position that satisfies the minimum accuracy. If no such position is found, the structure will not be spawned.
  • Items: List of structures to choose from where each structure has a certain weight that affects the probability of being chosen.

Let's place 3 to 5 chests in the level, with a minimum accuracy of 100%:

Structure config

And the result might look like this:

Example

Tips

Structures vs multi-tile rules

Multi-tile rules are great for handling simple cases that are easily expressed in a rule. For example, you can easily create a rule for a column that consists of 3 tiles stacked vertically.

Structures are great for handling more complex cases or for when you need to spawn an exact count of objects in a level. For example, if you want to spawn exactly 3 elite enemies in a level, it's impossible to do that with normal rules but quite easy with structures.

Limitations

Too many structures

The performance will degrade if you want to spawn too many structures or if the level is too big. You should be fine if you have less than 20 structures.

Structures too big

The performance will degrade if your structures are too big. You should be fine if your structures are smaller than 30x30 tiles.