Skip to content

Procedural Town Generator (Unreal Engine 4)

Examples3

Example of combining preassembled chunks of actors with their own associated rules to create a combination of specifically tailored map segments and a procedural rule set. The example takes an input integer to determine the overall map size to be generated, and then proceeds to decide where roads and empty lots should be placed as cells. Once the roads and empty lot cells are generated (each cell being 1×1), the game then figures out which cells contain a road that goes off of the edge of the map (black markers), and from that list chooses to where to place the player spawn (blue marker) and the enemy AI spawn (red marker).

Once that’s decided, each cell then selects from the corresponding lists of model pieces and individual components that match its previously figured out requirements. As an example, a cell might be defined as containing a straight road. It selects a random road variation from the list of current models. It then creates two sidestreet class actors and joins them so they line up at the sides. One sidestreet class might decide to become a sidewalk class, which contains its own functions that allows the chance to occur of creating 0-4 buildings on top of it. It chooses 3, and selects from different building models that can fit within its space. The other side of the street decides to become a parking lot instead of a sidewalk with an empty lot, and so chooses to become a parking lot which may or may not be filled with a randomized assortment of cars, and each car can be randomized in both rotation of parking, what model it uses, and the color of that model.

The variation should exponentially increase as assets of models and classes get added to the library; allowing for sweeping global changes to the entire game with the push of a button or the changing of a float.

Expansions on the codebase could include an option for a certain number of AI to be created inside buildings scattered throughout, as well as a specifically marked location, whether they should automatically patrol through different cells, defend a building, generate hints of where they can hide or take cover, etc..

A new series of functions could be used during duration to determine how the game plays out for that specific map, such as the simple neutralize all enemies objective, defend a building/item, escort a VIP, prevent robbers from running to the street borders of the map after fleeing a bank generated in the center, etc.