Procedural Generation: An Overview

Kenny
7 min readFeb 19, 2021
Procedurally generated cubes

Introduction

Hello and welcome! I’m writing this post on the general overview of procedural generation within game development.

The main topics I want to cover include: procedural generation history, the uses of procedural generation in games, procedural guidelines, random generation vs. procedural generation, and the pros and cons of procedural generation. So, sit back, relax, and enjoy the adventure!

What is Procedural Generation?

Procedural Generation, also known as Procedural Content Generation (PCG), is the creation of data using an algorithm, as opposed to manually creating the data. This data is generated during runtime.

Scenario

Imagine you’re walking in a meadow with mountains surrounding you, birds chirping, elk grazing on the grass nearby, and wildflowers all around your feet. You feel alive and say to yourself, “Wow… This is beautiful!” As you arrive back home from this amazing experience, you remember your game development skills that you’ve been learning. After quickly booting up your PC, you open your favorite game engine and try to manually recreate this extraordinary mountain meadow experience. You fail miserably after realizing the amount of work involved in manually creating a landscape. Just as all seems lost, the term procedural generation comes into your head. After conducting enough research, you become an expert in procedural generation and soon generate your beautiful mountain landscape using an algorithmic approach rather than manual creation. Success!

Scenario Explained

Now, the scenario I gave above is a bit extreme. Landscapes or environments can very well be created through a manual process without even using procedural generation. Likely with enough experience, you could manually create a similar setup to the mountain landscape I explained in my scenario, instead of using procedural generation. However, the point I was trying to get across was that procedural generation is often desired in the generation of terrain or landscapes to reduce the amount of manual labor. Moreover, if you intended to create a very detailed landscape that appeared to be infinite in size, this would be close to impossible to create manually. This is where procedural generation can be used to generate this type of landscape.

The reason I chose landscape generation for my scenario is because I’m very passionate about it. Apparently a lot of other people are too because this seems to be one of the most common topics for PCG when searching the web. Landscape generation is not the only form of PCG however. In fact, there are many forms ranging from generating animations to music and more!

Procedural Game History

Ah yes, our favorite topic. History! It seems that people either love it or hate it. I’ll keep this section relatively short, but I believe it’s always important to know the history of something that you’re learning.

While its difficult to find on the web which game was the first to use PCG, two of the most notable games are Rogue(1980) and Elite(1984). Rogue started a new genre of video games called rogue-like games. These featured procedurally generated levels where the player navigates a labyrinth type environment (referred to as a dungeon). Although some of these games predate Rogue, such as Beneath Apple Manor(1978), Rogue is considered the ancestor of all rogue-like games.

The early history of games had memory limitations which is one of the driving factors of their decision to use procedural generation so they could compress the data and decrease their file sizes.

Nowadays, computers are more advanced and don’t have as many memory or hardware restrictions. Even still, PCG is commonly used as a way for data compression. Modern uses of PCG often include creating terrain, levels, storylines, or other data that is unique for each playthrough.

Procedural Generation in Game Development

General Uses:

Procedural generation is generally used for increasing the replay value, data compression, reusing data, and for greater scalability in games.

Specific Uses:

Within game development there are many areas where procedural generation can be used. I’ve listed a few of these areas below, and although these are not all of them, they seem to be the most common ones used in games.

· Levels

Often 2D games will use algorithms to generate levels in their games. This approach is seen in rogue-like games.

· Terrain/Landscapes

Many open world games procedural generate their landscape in some way. No Man’s Sky, a game developed by Hello Games, used procedural generation to create an entire galaxy of planets, each containing their own atmosphere and wildlife.

· Animation

Animation, such as character animation, is another use of procedural generation. PCG may help the animation appear more unique and flow smoothly.

· Dialogue/Storylines

Often to create a unique playthrough, games will procedurally generate the dialogue. Moreover, the decisions the player makes in the game may affect the storyline and allow the storyline to generate its own content based on how the character responds to a certain event.

· Object Instantiation

Instantiating objects is one of the most common uses of PCG in games. Often this is referred to as spawning. The objects that are spawned may be enemies, animals, trees, loot, particle systems, and more!

· Loot Systems

Often quest-based games will use an algorithm to create a loot system. This algorithm may generate loot based on the player’s current level. If the player has a high rank, the generated loot will likely be more rare as opposed to that of a low ranked player.

Summary

After realizing how procedural generation can be used, its pretty crazy to think about all of the different types of content you can generate in your game!

Procedural Grid Example

Although this post is mostly focused on the overview of PCG, I created a basic algorithm to provide a visual demonstration:

C# script in Unity

Algorithm Explained:

Using nested for loops, my algorithm generates a grid of objects.

Given two variables, maxY and maxX, you can specify the amount of objects you want to spawn in both the horizontal and vertical directions.

Additionally, I have added two optional variables called offsetX and offsetY. These can be used to offset the grid from the default origin point.

yield return new WaitForSeconds(0.03f) allows me to create a small delay before the next object is spawned.

Lastly, Instantiate is a method in Unity used to create objects which takes in the object to be spawned, the spawn position, and the spawn rotation.

The result is shown below:

Generating grid of spheres

Procedural Guidelines

Ideally when implementing procedural generation, you want the data to appear unique. In doing so, you want to create a list of rules that ensures whatever you generate doesn’t break your game. For example, if you built an algorithm that spawned enemies, you wouldn’t want them to spawn out of bounds. Generally, you’ll have a desired outcome that you want to achieve, and the generated data has meaning or is recognizable as something that could have been manually created. If you don’t have a set of guidelines when building a procedural generation algorithm, the results will likely be undesirable, which is commonly seen as random generation.

To summarize the above guidelines, you are essentially trying to teach the computer how to build something that a human would normally make.

Random Generation vs. Procedural Generation

When researching procedural generation, this topic is a very common one that pops up. Is there a difference between random generation and procedural generation? These two terms are often used interchangeably. From my understanding, random generation is a part of procedural generation, but procedural generation is not always random.

As I mentioned earlier, procedural generation will usually have a set of rules to produce a desired outcome. Whereas, random generation is the part of procedural generation that doesn’t follow any guidelines and will produce undesirable results. These undesirable results may very well break the game.

Often procedural algorithms will have a variable called the “seed” which can be used to control the outcome. If the seed remains the same value, then the algorithm will generate the same content each time. If the same content is generated each time, this is still procedural generation even though the data remains the same.

Pros and Cons of Procedural Generation

Pros:

  • Smaller file sizes
  • Less effort to add lots of content
  • Less repetitive gameplay
  • Better replay value
  • Increase in reusability
  • Greater consistency

Cons:

  • Difficult to visualize your algorithms as you construct them
  • Hard to change algorithm after its built
  • Without a defined set of rules, procedural generation can end up being very messy and potentially break your game
  • May take more time to create an algorithm than manual creation

Fun Fact

The Lord of the Rings movies used MASSIVE, a procedural generation software, to generate the huge armies in their scenes. Without this software, it would have been very difficult to include the army sizes they had.

There are many other movies who have used this same technique.

Demo Video

The following link is a video of me demonstrating procedural generation in action:

Conclusion

I’d like to thank all of you for taking time to read my post on the overview of procedural generation. I hope you learned a thing or two about what procedural generation is and different areas that it can be used within game development.

If you ever find yourself manually creating assets in your game, ask yourself, “Can I use procedural generation to produce the same outcome?”

References

--

--