Guest Blog: “Procedural Content Generation” by Aaron Chapin

Here at Goodgame, we are a multi-talented team with many different specializations within the field of gaming. What unites us is our passion for making games, and our ambition to become really good at what we do. In order to achieve this, we want to learn and improve fast, which is why it is especially important to us to exchange knowledge throughout our team as well as with the rest of the gaming industry. That’s why we are quite excited to share our first guest post from our colleague Aaron with you today! Aaron has worked as both a client and server developer within our Moonshots Studio, and in his blog post, he lets us in on the topic of building parts of a game automatically using Procedural Content Generation. Read on to find out what that is, how it can be used, and what benefits or drawbacks it might have.

Alex at Unite
Unite 2016 Europe – Image ©Dan Taylor/Heisenberg Media. – Source: Flickr

“If your game world is the size of an actual galaxy, populated by millions of full-scale planets, how long is it going to take you to build all of them? If you had one person working on it, hand-carving every river, raising every mountain, and boring every cave, they probably wouldn’t even be able to finish one before the game needed to release. How do you build systems that allow players free reign in-game, and have everything continue to work smoothly?

I recently had the pleasure of presenting at Unite Europe, which is a conference for developers that use the Unity game engine. My talk was on a topic that I love, Procedural Content Generation (PCG). At its heart, PCG is about using data and algorithms to build parts of the game that can’t be pre-built or hand-built by humans. Sometimes these limitations are due to how complex the content is, how large it needs to be, or just the overwhelming number of individual things. Rather than solving this problem by making more artists or designers work on this task, you can write code that builds things for you, based on information that you feed into it.

A classic example of this is a spline-based mesh generator. If that sounds scary, don’t worry, it’s actually a very simple concept! If you needed a fence in your game world, you could have a level designer place each post and board individually, and slowly build the fence. However, if something changed, and the fence needed to change shape, that level designer would need to go back and move those posts and boards themselves. A procedural approach would start with defining a small chunk of the fence, most likely just a single post, and the boards that connect one post to another. Then, in the level, the designer can just draw a line on the ground where they want the fence to go. The procedural generator would go along this line, placing posts and connecting them with the boards. This way, if the fence needs to move, the designer just needs to delete the old fence, draw a new line, and let the generator go along the new path. So once you have taken the time to program the procedural path generator, you save your designers time, and you can even reuse that code with other chunks to generate other things as well.

Fence Generation

Using PCG can really help speed up development, but it has some drawbacks that can’t be ignored. In general, you can’t build everything directly out of code; you need to have some small pieces of information that get fed into your generator. These can be random numbers, or textures, or even small 3D models. You also need to develop the formulas that take the inputs provided and turn them into usable outputs for your game. In my talk, I showed off a generator that built looping racetracks for a simple racing game. If my generator built tracks that were only 1 meter long, or crashed into themselves, they wouldn’t be useable in-game. Even with such a special case, there were lots of ways to build the content I wanted, and each had its own advantages and disadvantages. One of the hardest problems to solve with PCG is making sure that all of the output generator is going to be interesting! No one wants to play a game where every character looks exactly the same, aside from a slightly different hair color.

Track Generation

There are lots of ways that you can utilize PCG when building games with Unity. However, there are certain things that Unity provides developers that make it very easy to get started! In particular, there is a Mesh class that can be used to build 3D meshes programmatically, rather than waiting for a 3D artist to build a model. There is also support to let programmers build tools inside of Unity both for themselves, or to allow other team members to add their new content directly into the project. Unity is a huge and complicated ecosystem, so it’s possible that someone has worked with it for years and never heard of some of these powerful tools. Through my talk, I tried to give a light introduction to a few of these concepts, so that people who were interested would have some of the vocabulary and conceptual understanding to learn more on their own.

Alex at Unite II
Unite 2016 Europe – Image ©Dan Taylor/Heisenberg Media. – Source: Flickr

It was a lot of fun being at Unite and sharing some of the knowledge I’ve accumulated through my career as a game developer. It was also my first visit to Amsterdam, which was great, even though it doesn’t have as many canals as Hamburg!”