Godot Infosheet

I often use Godot for games and other code projects. I'm no expert, and sometimes I end up spending quite a long time searching for details on how to use a certain feature.

My goal for this page is mostly to compile some notes, mostly so I don't have to go down the rabbit hole more than once for the same information!

Autotiles in Godot

Godot's TileSet editor now offers Autotiles, which are scripted tiles that handle edge-tiles and variations automatically.

The Autotile portion of the TileSet editor offers several different modes, where you'll set up how the tile behaves (these are just the main ones):

  • Region is where you select the area of your spritesheet that contains the sprites for a particular tile. You'll select all the different edge and center tiles here.
  • Collision is where you set up collision polygons for each subtile.
  • Bitmask is where you set up which edge will be placed where.
  • Priority allows you to control the probabilities of different tile variations.
  • Icon is where you can set a fallback tile, for situations when the autotile doesn't know which tile to place.

For edging, the Bitmask mode is the critical part to set up, and there are several different ways to go about it. In the editor, you'll be able to draw red squares over each tile, which you'll use to indicate where neighboring tiles of the same type are in each situation.

There are 3 different bitmask modes, which determine how many red bits you can draw on each tile. They are: 2x2, 3x3 (minimal), and 3x3.

2x2 is the default, and it allows you to indicate sides, corners, elbows, and centers. It's best for if you only plan to paint bigger, simpler areas with the tile, as it does not work for smaller single-tile details.

3x3 and 3x3 (minimal) offer more control, but they also require more tiles. In these modes, you can set bits in a 3x3 mask on each tile, which directly represents the tile and each of its neighbors. The difference between 3x3 and 3x3 (minimal) is that the minimal mode ignores certain corner cases for simplicity.

If you need the extra precision of the 3x3 modes, but you don't have tiles for everything, you can also tell the bitmask to ignore certain bits, in order to get a certain tile to cover a few different contexts. To do this, shift click the bit. This paints a blue checker over the bit, indicating that it will be ignored (and the tile will be placed regardless of whether a similar tile is in that location or not).

When painting autotiles in the TileMap, the tiles will appear based on which bitmask matches each tile's neighbors. If the autotile is unable to find a match, the Icon tile will be drawn instead.

You can also set up multiple tiles with the same bitmask, at which point the editor will choose one of the matches at random. This is where Priority comes in, as it lets you increase the probability of certain tiles being selected. You'll notice that each tile's priority value is listed as "X / Y". Think of these numbers a bit like raffle tickets. X is how many tickets you've given this particular tile, Y is the total number of tickets for all the tiles in that context. In turn, X / Y is the probability of that tile being drawn for its given context.

A simple example of this might be a grass autotile. You could load in a basic grass tile and a dandelion, which you want to only appear occasionally (we should all be so lucky). To achieve this, simply increase the Priority on the basic grass to, let's say 29. This will make the basic grass appear 29 out of 30 times, and the remaining 1 in 30 you'll get a dandelion!