Initial Constraints
Initial constraints configue the intial conditions of the generator. They generally set up by adding behaviours into the world.
- Pins fix a particular tile in place
- Volume constraints filter a particular area to a subset of tiles
Pins
Sometimes you just want to place a tile at a particular location without Tessera choosing for you. For example, you might want to place a entrace manually at one side, or write custom code to draw path ways for you. Pinned tiles lets you do this, and then have Tessera generate the rest of the tiles for you.
There's multiple ways to specify pins - all of them involve putting a game object inside or adjacent to the generator area, in the position of the cell you want to affect. They will be automatically detected and incorporated into the generation.
The most flexible way is to great a game object with the TesseraPinned component. You can then specify the PinType and the tile to pin as properties of that component.
As a convenient short cut, you can also just place a Tessera tile directly. These will be interpreted the same as a TesseraPinned component that references that tile, and has pin type FacesAndInterior.
You can also place an object with both a Tessera tile component and a TesseraPinned component. The TesseraPinned will be assumed to reference the tile component on the same game object.
Here is an example. A generator is set up and a few tiles manually placed.
When the generator is run, the new tiles join up with the placed tiles.
Configuring pins
TesseraPinned has two key properties:
- Tile determines what tile to use for pinning.
- PinType controls how exactly the pinned tile effeects generation.
These two values are inferred in some cases, as described above.
There are three types of pin:
With this pin type, the generator is forced to generate the referenced tile at the location of the pin.
The referenced tile must already be in the generator's tile list (though it can have weight 0).
With this pin type, the faces of the referenced tile are used to constrain the cells adjacent to the location of the pin, and the generator is free to pick any tile for that cell.
With this pin type, the faces of the referenced tile are used to constrain the cells adjacent to the location of the pin. Also the cells covered by the pin are masked out so no tiles will be generated in that location. You may therefore need to manually place a tile or other game object to fill the gap. Unlike PinType.Pin, the refenced tile does not need to be in the generator's tile list.
The different pin types can be used to generate a variety of effects. FacesOnly, for example, is good at restricting the generation along a given plane, without forcing any particular tile. FacesAndInterior allows you to put in custom tiles (often called "hero" pieces) that never otherwise appear in generation. And Pin is good for forcing a particular tile to be placed, while still allowing that cell to be part of generation. That can be important if you need the cell to interact with generator constraints or other Tessera features.
Volumes
Add a GameObject with the Tessera Volume component to filter an area of cells to only use a subset of tiles.
To use it, add a game object with the volume component, and set the cells you want to filter to. You can optionally specify a generator for convenience, but it's not necessary.
Then you need to specify the actual volume of space that the collider affects. You do this by attching more components to the volume's game object. You can either use Unity Collider, or you can use any Tessera Tile component. Tessera will consider a cell of the generator to be inside the volume if the center of that cell is inside at least one collider or tile component.
Here's a dungeon generated with a box collider volume in the center, configured to filter to just an empty tile.
Unlike pins, volumes have no way to configure the rotation and reflection of the generated tile.
Volumes can also be used to remove tiles from the generator entirely, by setting the volume type to MaskOut. This behaves similarly to pinning tiles with FacesAndInterior - the missing cells interact differently with constraint.
API
The default behaviour of generators is to search the scene for appropriate pins and volumes. This can be slow for large scenes, and it's not suitable for advanced customization.
You can use the C# API to set pins and volumes directly.
- First, disable the automatic detection by setting
searchInitialConstraints
to false. - Get a builder by calling
generator.GetInitialConstraintBuilder
. - Call the methods on the builder to create your own initial constraints. The objects passed do not need to be in the scene, they can be prefabs.
- Construct a
TesseraGenerateOptions
and fill theinitialConstraints
field with an array of your created constraints. - Pass in the options as an argument when calling
Generate
orStartGenerate
.