
WFC Procedural Map Tool
Tools Programmer
Core information:
-
Developed a Modular Unity Package for procedurally generating maps using the Wave Function Collapse algorithm.
-
Designed the tool's workflow to avoid possible errors and reduce the complexity of use, while maximizing flexibility.
-
Created multiple Custom Interfaces for the tool.
Conception
This was not my first attempt at creating a tool based on the WFC (Wave Function Collapse) algorithm. However, my previous iterations were filled with workflow problems:​
-
Setting up each map variation was extremely time-consuming and repetitive.
-
The tool had very poor scalability and performance.
-
It was easy to commit human errors while configuring the tool. At the same time, those errors were hard to identify.
-
The tool lacked core features and was hard to maintain due to a poor architecture.
-
It was hard to learn and not accessible to users who could not code.
With the previous issues in mind, I set to solve them in a final iteration.
Designing a Workflow
Maps that use WFC are usually subdivided into smaller maps to improve efficiency.
To blend maps parts, both sides need to share some map tiles.
Each map subdivision will require a new configuration of tile-adjacency constraints to create variety.
Users will likely work with multiple maps at once.
Some tiles will be shared between map versions.
Each map should have private and unique adjacency constraints.
Users will likely work with multiple maps at once.
The configuration of each map is now stored as Scriptable Objects.
This allows users to:​
-
Reutilize Tiles between maps.
-
Easily duplicate maps.
-
Swap map configurations in a single action.

Image: A map configuration's custom editor.
Additionally, tiles do not need to be manually added to each map. Instead, the user specifies the folder paths where tiles are stored and the map automatically collects all the relevant tiles (Ex. A 2D-square map will only collect 2D-square tiles).
Some tiles will be shared between map versions.
Each map should have unique adjacency constraints.
The new Custom Window Interface lets users configure the tiles and adjacency constraints of each map efficiently:

Image: A map's custom editor window.
Users can now:​​
-
Enable and disable what tiles are used in the map with a single click.
-
Swiftly visualize and manage each tile's connections.
-
Give more weight to certain tiles to ensure they appear more frequently.
Designing for errors
With my previous iteration of WFC, it was easy to make errors. The new version has been designed with errors in mind, making it much more efficient and usable.
Before
Now
Users needed to manually create a connection on both connected tiles.
Ex. To connect "A" and "B", users had to create the A - B connection and the B - A connection.
Otherwise, the connection only existed in one direction and not the other, breaking the system.
Users only need to create a connection on one side and the other side is updated automatically.
This halves the work required for a similar result and makes it impossible to recreate the error described on the left.

Image: A tile connecting to itself.
The menu automatically updates all the values affected by the change so that they stay consistent.
Users could create connections with tiles that were not part of the map.
Users can only connect tiles that are enabled. Tiles are added and removed from the menu automatically to ensure this.
Ex. A user could connect "A" and "B" even though "B" was not designated as a valid tile in the map.
This saves time that would otherwise be spent scrolling through tile lists. It is impossible to recreate the error on the left.

Image: Enabling and disabling tiles in a map.
Those tiles are automatically added and removed from the menu on the right.
Users had to manage multiple different script classes, each with multiple functions and different code demands.
The amount of coding required from users has been reduced to a minimum:
All maps are controlled through a single class, regardless of type (2D or 3D, square or hexagon grids). The class is controlled by only 3 functions.

Image: Functions used to control a WFC map.
The WFC algorithm sometimes reaches a lockdown, an unsolvable position.
​
This cannot be avoided or predicted. Before, lockdowns just resulted in an error being produced by the script.
I implemented a Drop-Out Stack to record changes to the grid as it collapses (a stack with a limited size. When it is full, adding a new element deletes the oldest element to make space).
This allows the algorithm to backtrack when it makes a mistake. It also lets users decide how many steps they want to track, which gives them incredible flexibility when deciding how much memory to use.
Another tool I've made:
Second Order Transform Tool
Core information:
-
Developed a modular tool for procedurally easing movement, scaling, and rotations of Unity GameObjects.
-
Created a Custom Editor Interface for the tool.
This tool can dampen changes to a Unity Transform's values (Position / Rotation / Scale) in a manner that feels hand-crafted despite being procedural.
Users can alter how the dampening effect is applied thanks to three configuration values and a custom editor tool that previsualizes the dampening in a graph.

I'm currently working on releasing this tool to the public through the Unity Asset Store. Thus, I have gone through the polishing and documenting it to bring it up to Unity's standards.
This tool is an expansion of that shown in t3ssel8r's video, "Giving Personality to Procedural Animations using Math".
