Skip to content

Consumedgrub2/UnityGridPrefabProcGenSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnityGridPrefabProcGenSystem

The long awaited open sourcing of the grid based prefab procedural generation system for the unity game engine. I've always wanted an example project or source code base to help aid me in procedural generation (Procgen), specifically prefab-based procgen, but there are no example projects out there. When I say prefab-based, I don't mean individual rooms that are built with individual prefabs using procgen, but whole rooms that are the prefabs themselves. I also wanted a system that was similar to the procgen systems found in games like SCP: Containment Breach and basically all of the other SCP games. I ended up going on about a 2 week journey to build this system from scratch using information from outdated forums and a few videos. This is what I ended up making in 2 weeks:

ProcGenTestImage

It was trial and error and lots of all nighters within those two weeks but I finished a fully functional system. It's based off an idea called Wave Function Collapse which takes inspiration from quantum mechanics. As one room is placed (Collapsed), the rooms around that one are whittled down in terms of what they can be until they eventually collapse to conform to the rooms around them.

Wanna see it in action without opening any code? Get a build of the example unity project for Linux and windows in the Releases tab.

Features

  • Customizable room prefabs (Make your own prefabs, drop them into the system and generate)
  • Random room prefab rotation for 4-ways and RequiredRooms
  • A RequiredRooms system where each required room that gets generated must be a 4-way and its connections are disabled based on surrounding rooms on the grid during runtime (This was done this way to make the system more maintainable and have a smaller footprint)
  • Door spawning system
  • User input-based seed system (Can be hardcoded or input from other systems)
  • Room rotation and Room prefabs are based on floor level seed, which is based on the map seed, which that is based on user input seed
  • Included example for a simple room and generic object culling system for performance
  • Included room prefab example models that are MIT licensed as well (Everything in this repository is MIT)
  • Included example unity project build
  • Oh yeah, all of the code is commented for your convenience <- Godsend right there (I will eventually make a wiki for this repository explaining how the system functions in detail)

Usage

If you want to reference just the code for aid in your procgen system design, the system-specific code is under the ProcGenSystem directory. If you want a fully setup example unity project that has all of the scriptable object room connection definitions and rotation definitions, you can use the project under the ProcGenTestProject directory. The unity project was built in unity 2022.3.62f1 but the system itself probably works with some older unity versions and I imagine it would work with any modern version of unity.

About

The long awaited open sourcing of the grid prefab procedural generation system for the unity game engine.

Resources

License

Stars

Watchers

Forks

Packages

No packages published