Procedural Generation has gained a lot of momentum in a current times, for multiple reasons, but many of us are still oblivious to the fact of what it actually is so here is a tutorial introducing and explaining the concept of Procedural Generation.

In this tutorial we will learn some of the important topics related to or involved in getting started with procedural generation.



This tutorial is helpful for all types of programmers and designers as it’s a explanation of concepts rather than a programming guide so just dive in.

So let’s get started,

First let’s get started with the official definition of Procedural Generation,

In computing, procedural generation is a method of creating data algorithmically as opposed to manually. In computer graphics, it is also called random generation and is commonly used to create textures and 3D models. In video games, it is used to automatically create large amounts of content in a game.



I just copied it from Wikipedia.

Now my version of definition goes like this,

Procedural Generation in games is the generation of data for use as the content ,i.e. assets and stuff, of the game via code. Simple.

Now to understand some important uses of Procedural Generation to motivate this the effort of learning about it,

Procedural Generation allows us to work with minimum assets creation while providing maximum replay-ability of the games we make which makes a lot of sense in Indie gamedev. Due to time and resource constraints.

Procedural Generation allow for reusing assets in multiple ways that make the game smaller in size as compared to something hand-crafted this makes for a better alternative for the gamer who would NOT need to download a 100GB game because of it.

Lastly it makes, lots of effects like water waves and such possible which would be impossible to make by hand. At the end of the day it’s possibilities are endless.



In the recent times we have had an immense increase in the ability of creating content with the thing called Machine Learning,

This is an image from Neural Doodle repo from Github. This makes awesome artwork from silly doodles, so just imagine the possibilities this might hold for game development.

But currently this is a slow process with not much optimization abilities so it will be some time before we have this in actual game development pipelines but Machine Learning has already started to make impact.

Moving on with our tutorial let’s create some basic procedurally generated content,

There are mostly 2 types of procedural generation we will deal with today,

Randomized. And, Rule Based Randomized or Evolution. These aren’t really the accurate names but hope they will help you understand things better.

Step one,

Let’s get some assets, create a new Godot Project and create new Scene with Node2D as root and save it.

And then add the icon sprite to the scene and go and hit it’s modulate property to make it look different from usual.

And then finally create a tileset from the scene and get ready to use it in a project.

*Make sure the tileset has atleast 2 items.

Also make sure to save the scene we will use it later.

Step two,

Now create another scene and add a root(any node) and a TileMap node.

Next just add the Tileset we created to the TileMap node and leave everything else as it is.

And don’t worry about the colors not showing up in the Tile-Selector in the left.

It will be fine in the end.

Step three,

Add a script to the TileMap node and start typing,

Create a new variable called grid.

And then in the _ready() initialize it to make the grid into a 2D array that holds data.

Use the randi() function to create the data needed.

Here we generate random numbers per position on the grid which we can use to generate our content later, I have made the whole thing 17 by 17 you can go beyond that too.

Step 3.5,

Use the grid to generate a random map.



Now hit play and test your code,

you now have a randomly generated map.







Want to do more. Fine let’s do more,

This time just add some rules to the randomization,

Like make all tiles next to the edges black and and add a hole randomly as an exit.



And then this is the result we get,



So in this tutorial we learned to create a Procedural Room with nothing but randomization and some very basic rules.





In future I plan to create more complex tutorials about procedural generation and make it so that the Godot Community can use it to make awesome content, but that is if this tutorial is received well within the community.