Creating and Working with Prefab Brushes in Unity (2D Extras)

Following on from the previous article on Animated Tiles, another nifty little thing we can work with using Unity’s 2D Extras are these Prefab Brushes. As the name suggests, they allow us to ‘paint’ our own prefabs onto tilemaps within our scenes. This can particularly come in handy when you need to, say, dot some coins or other collectibles around your scene (and which might well have custom scripts and behaviours).

If you’ve imported the 2D Extras assets, you should be able to right click in your Project view and navigate to Create > Brushes > Prefab Brush.

With your newly-created Prefab Brush selected in the Project window, you can take a look in the Inspector and set things up there to your liking. In particular, we can increase the size of an array of prefabs and can drag in any prefabs we’d like from our project.

These additional prefab slots can come in handy if we want to have a bit more randomisation when painting onto our scene, for instance if we wanted to have a mix of bronze and silver coin prefabs (each worth a different amount).

Once you’ve set this up, you should be able to select this brush from the brush dropdown towards the bottom left of the Tile Palette window:

With that (and the paint brush icon selected) you can now paint your prefabs into your scene 😉

Game Developer | Game Design and Literature Graduate