Customize output
You might often want to modify the structure of generated levels, e.g. by adding a collider to a specific layer. Let's see how you can do that.
Short version
The generator comes with a reasonable default structure for generated levels. The first time you generate a level, a new Game Object called Generated level
is created in the scene which holds the whole generated level. The generator saves the reference to this game object and each time you generate a new level, the generator reuses the same game object.
You might often need to slightly modify the generated level. For example, you might want to add a collider to a specific theme layer. This is usually very simple because the level object is reused, so you just find the game object that belongs to the theme layer and you add a collider component with whatever configuration you need. If you generate a new level, the changes you made should be persisted.¨
Some properties will get overwritten if you manually change them, please read the next section for more details.
If you accidentally break the generated level object, you can always just delete it and the generator will create a new one for you.
Long version
The generator comes with a reasonable default structure for generated levels. The first time you generate a level, a new Game Object called Generated level
is created in the scene which holds the whole generated level. The generator saves the reference to this game object and each time you generate a new level, the generator reuses the same game object.
The structure of each level looks like this:
- Root game object, called
Generated level
by defaultIntGrid
object, it holds the int grid layerNameOfThemeLayer1
- contains the first layer of the themetile
rules are placed inside the Tilemap attached to the objectgame object
rules are placed as children of the object
NameOfThemeLayer2
- contains the second layer of the theme- ...
Objects
- contains game objects that do not belong to any layer, e.g. the spawn or goal game objects if used
The structure above is relatively fixed because the generator needs all the objects and they are matched based on their names. If you try to rename or delete some of these objects, the generator will attempt to recreate them the next time you generate a new level.
There are also some components and properties that the generator will always override no matter what you manually configure:
- root game object must have a Grid component
- cell properties are set based on the theme
- root position is set to (0,0,0)
- int grid object must have Tilemap and Tilemap renderer components
- tilemap orientation is set based on the theme
- sorting order is set to 1000
- position is set to (0,0,0)
- theme layer objects must have Tilemap and Tilemap renderer components
- tilemap orientation is set based on the theme
- position is set to (0,0,0)
- sorting order is set based on the order of the layers in the theme
- sorting order is only overridden when a layer is reordered in the theme, so you can change the sorting order manually if needed
- tiles and children are removed every time a theme is applied
Apart from the fixed structure, you should be able to modify the level in any way you need. You can add more game objects, you can add components or you can change the configuration of existing components.
You can also manually change the game object that the generator uses for generated levels. You do that by setting the Output
property on the generator component.
You should be aware of dangling objects. For example, if you rename or duplicate theme layer objects inside the level, the generator might lose the connection to the original theme layers. When that happens, the generator will just leave the extra objects intact as it does not know whether the objects were placed there intentionally. You either need to manually remove them or just delete the whole generated level object and let the generator create a new one for you.