![]() |
ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
|
The following subsections outline how to procedurally generate an arrangement of rooms, called a Layout
.
The procedural generator creates layouts by pulling from user-defined room templates. To the generator, a room is a collection of cells in a grid, with information, such as the available door connections, assigned to them.
Mania Map > Room
.In the below screenshot, the cells for an angle shaped room have been created, with the active cells shown in blue and inactive cells shown in red and crossed-out. The active cells are the regions where we intend to build our scene.
Doors define the locations where two rooms can be connected. At least one door must be added to a room.
Mania Map > Door
. To save time, you may wish to save your doors as prefabs with any related components, such as sprites or collision. These prefabs can then be referenced in your room prefab.Auto Assign
button on the room toolbar. The assigned door direction will be based on its location relative to the center of its assigned cell.Additional room child nodes such as CollectableSpotComponent
, Feature
, and RoomFlag
can also be added to the room if you wish them to be included.
The below screenshot shows a square 3x3 room with doors around its entire perimeter. Each of the door direction (north, west, east, and south) use a different prefab since the tiles depicting the doors are different for each.
The procedural generator uses one or more RoomTemplateResource
exported from a room to generate layouts.
Mania Map > Batch Update Room Templates
.RoomTemplateResource
Scriptable Objects with the .room_template.asset
extension to the prefab paths.One or more TemplateGroup
are used by the procedural generator to determine which rooms can be assigned to a given position in a layout.
Create > Mania Map > Template Group
.RoomTemplateResource
into the rectangular region to add them to the group.Note: Locking the inspector and searching
t:RoomTemplateResource
in the project explorer can make adding room templates to a group easier.
The procedural generator uses a LayoutGraphResource
as a base for generating layouts. This allows you to design high level relationships between rooms while still making the resulting layout appear random.
Create > Mania Map > Layout Graph
.Create Node
to add a node to the graph. Each node will serve as a room location.Add Edge
, then click on a second node to make the connection.TemplateGroup
assigned; though it is optional of edges.The GenerationPipeline
takes various inputs and feeds them through a series of operational steps to generate one or more outputs. In the context of this package, the output is most notably a room Layout
.
Mania Map > Generation Pipeline
. A pipeline with the default inputs and steps will be created.Inputs
Game Object, add one or more LayoutGraphResource
to the LayoutGraphsInput
component.CollectableGroup
to the CollectableGroupsInput
component.GenerationPipeline
you wish to run, and call the Run
, RunAsync
, or RunAttemptsAsync
methods to generate a layout. For example:Note: Depending on your room templates and layout graph, it may not be possible to generate a layout for all (if any) random seeds. If you are encountering issues with successfully generating a layout, you may need to reconsider the constraints imposed on its generation. For example, you may need to add more doors to ensure that your rooms have a better chance of connecting. Even then, you may still encounter some isolated failures, in which case the generation pipeline
RunAttemptsAsync
method can help by automatically falling back to other seeds.