1 free read left. Create a free account for unlimited reading + AI research.
Create free accountcan we build an infinite bathroom using the beloved unity game engine toilets have always been one of my favorite things so it's been on my bucket list for a long time to generate a shift load of them we already kind of talked about how the island generator for our indie game islanders works today we're gonna ramp up the challenge and build an infinite public bathroom so here's the question why am i doing this instead of working on my game the answer is you thought there was an answer didn't you the level generator of islanders is fairly simple so i wanted to try something more sophisticated this time the almighty wave function collapse algorithm which is basically just a fancy way of saying we're gonna take a bunch of puzzle pieces and assemble them into a level so step number one was making some nice looking puzzle pieces i started out by creating some simple textures i could later use for the 3d models because obviously we're going 3d hell yeah baby you can see that i'm looking a little bit angry but that's actually not my angry face that is my i'm focused face my modeling skills were a bit rusty so this was a nice
refreshment i quickly got my first puzzle pieces built and put them into the engine for testing and was time for the main challenge writing the actual algorithm this is the first time i'm doing something like this so i had to look up how it works luckily there are some great resources like oscar schalberg and this amazing article i found on gritbox okay i think we're ready for the first test i'm a little bit scared what is this crap here imagine we want to generate some random pipes and the only puzzle piece we have at our disposal is this curved pipe right here at the beginning we can just put our puzzle piece at any position we want with any rotation we want but once you've placed it a lot of things are actually not possible anymore for example here you need to place the pipe either like this or like this so placing a puzzle piece restricts all of the neighbor pieces which can then restrict even more of their neighbor pieces because if you only have curved pipes then obviously placing a pipe like this is not possible so the almighty wave function collapse algorithm essentially builds a level as
if it was solving a logic puzzle unfortunately my wave function collapsed didn't quite get it yet so i called the sheriff we stood there sun burning oh no hold on why are you telling me you're finished you're not finished after a while i finally got it working but now it was generating these weird vertical lines in the level couldn't come up with any logical reason why it would do that so another round of bug fixing it was and the gizmos in theory should show how many different tiles can still go at a certain position in the end of course it turned out it was just one little minus that wasn't supposed to be there
i could already imagine all of the beautiful toilets with some newfound motivation i did some research on how to write a proper entropy function and when i say research i obviously mean i'm adjust you know grab this formula bing bong bing bong i did some more cody cody stuff modeled the ceiling tiles for my infinite restroom then i reminded you to wishlist will you snail on steam i'm so sorry you'll get it eventually and not to forget hours hours hours hours labeling my puzzle pieces because obviously you need to tell the program which sides can be connected and which can't ah yeah yeah what did i do i thought if my algorithm works on a 2d plane it will surely also work in 3d space
yeah i was mistaken it really never stopped surprising me look at that now it generated this why why do i feel like i'm shopping for toilet seats this one has like 32k vertices that's like too much for what i'm planning i was a little scared to model my own toilets because my modelling skills aren't really all that great but it went surprisingly well i also modeled some nice little toilet cabinets for some extra privacy i witnessed some more really strange and confusing bugs then i reminded you to wish list will you snail modeled even more puzzle pieces 75 in total labeled every side of every cube with my not at all complicated labeling system now before i show you my finished results there's one more thing we need to address the infinite part of the story right how do we make it infinite grab all of this hit duplicate because it tiles it tiles perfectly so we'll simply generate multiple versions of the level next to each other and then
loop the camera around at the edges what you're about to see is either a public bathroom or modern art you can tell me in the comments which one of the two you think it is [Music] [Music] [Applause] [Music] [Music]
eh dude why are you staring at me like that oh sorry i was just wondering if you had some toilet paper do i look like i have any excuse me does anybody have some toilet paper you
The development of an infinite, procedurally generated public restroom within the Unity game engine serves as a practical exploration of the Wave Function Collapse (WFC) algorithm. By transitioning from simpler level generation techniques used in previous indie projects to the more sophisticated WFC method, the project demonstrates how complex, self-consistent environments can be constructed by treating level design as a logic puzzle. The core methodology involves creating a modular set of 3D puzzle pieces—including toilets, cabinets, and structural elements—and defining strict connectivity rules for how these components interact in 3D space.
The implementation process highlights the technical challenges inherent in algorithmic generation, specifically regarding entropy management and spatial constraints. Initial attempts revealed common pitfalls, such as logical inconsistencies in tile placement and the generation of unintended vertical artifacts, which were resolved through iterative debugging of the algorithm’s constraints and labeling systems. The project required the creation of 75 distinct puzzle pieces, each meticulously labeled to ensure that the WFC algorithm could successfully navigate the rules of adjacency and rotation.
To achieve the goal of an infinite environment, the system utilizes a tiling approach where generated segments are duplicated and arranged in a continuous loop. By manipulating the camera to wrap around the edges of these generated blocks, the engine creates the illusion of an endless, seamless space. This project underscores the efficacy of WFC for developers seeking to automate the creation of complex, modular environments, proving that with precise rule-setting and robust asset labeling, developers can generate expansive, coherent 3D structures that function as both functional game levels and abstract digital art.
The games and companies this document names on the inner ring, other documents about them on the outer one. Select a cover to see it up close and open it in a new tab; drag to move, pinch or Ctrl + scroll to zoom.
Thomas Brush · 2025
Comments