Multiple passes
This tutorial continues from the Getting Started tutorial. It is recommended you complete that one before starting this.
So far we've looked at running the generator once, and filling in the entirety of the tiles at once. As an advanced technique, it's possible to run multiple linked generators in the same scene, each configured differently. Running separate passes like this can achieve a variety of effects, and usually runs faster and more reliably than a single generator.
The key idea is that when you run a generator in Tessera, it creates additional game objects to fill the scene. Additionally, before the generator runs, it scans the scene for any relevant game objects that should constrain the generation. So if we run two generators sequentially, overlapping in space, then the output of the first will act as pins constraining the second.
This tutorial will show you how to generate ground tiles in one pass, then add decorations using a second. The decorations will be constrained to only attach to relevant tiles.
In the previous tutorials, we made a generator that generates a series of paths through a grassy plane.
First, we'll add some extra paint on the top surface of the existing tiles to mark where is grassy, and where is path.
Now we need to make a new tileset for the decorations. With the assets supplied, make 3 tiles similar to the given ones.
Then, using "Show Backfaces", paint the undersides of the tiles as indicated.
Most of the tile is left unpainted, as we don't care what it connects to. All we want to ensure is that the trees themselves are never placed directly above a path.
Now, create a second generator. This generator should be a new game object which is placed directly above the original one by 0.2 units.
Set it up as follows.
Now run the two generators in order - starting with the path generator, then the tree generator. You should find that the trees are only generated where there is appropriate grass for them.
To make working with multiple passes easier, you can create a Multipass Generator that holds a reference to each of the generators you've just set up. This is a convenience for running both at once.
Further customization
Multiple passes are even more powerful once you realize that anything created by the first pass will be used by the second pass. That means you are not limited to just adding extra tile paint as done above.
See the Skyscraper sample for an advanced usage.
In this sample, the road network is generated by one generator, then the skyscrapers are filled in by another. But the two generators use different grids: the buildings have a tilesize one third of the road tiles. To make this work, we instruct Tessera to replace the road tiles with big tiles that fit the smaller grid.
The sample also activates/deactiveates pins so they only apply to particular generators.