Unity 2019.3 continues to bring more exciting updates to Unity’s Terrain system, including – by popular demand – the ability to create holes in your Terrain!
Using the new Paint Holes brush tool, you can mask out areas in the mesh of your Terrain Tiles, and even manipulate these masks through your code. This makes it easier than ever to add terrain characteristics like holes, portals, or even caves by taking advantage of in-Editor tools like ProBuilder, ProGrids, and Polybrush. Let’s take a look at how we can create a simple cave using this process.
From the Terrain Tools drop-down menu, select the Paint Holes brush. With your Terrain Tile selected, pick your brush shape in the Inspector and make sure the opacity of your brush is set to 100. Paint a round shape where you plan to place the entrance of your cave.
ProBuilder and Polybrush are in-Editor tools for simple 3D modeling that can be used to create a basic cave. You can easily add both to your Project via the Package Manager. Once both are installed, you can start creating your cave with ProBuilder.
Open the tool by navigating to Tools > ProBuilder > ProBuilder Window. Using the ProBuilder menu, create a new ProBuilder shape and select the Pipe preset. Identify which end of the pipe you’ll use for the cave’s entrance. Create a new Plane shape that’s slightly larger than the pipe’s radius, and use it to seal the other end of the cave. Select both objects in ProBuilder and merge them to create a single GameObject. Using the ProBuilder face selection tool, delete any extra faces on the plane that are outside of your sealed cave. Scale your object to match the radius of your Terrain hole, and move it into position.
Using Polybush, push/pull the vertices along your cave entrance until they align nicely with your Terrain hole. You’ll also want to use Polybrush along the length of your cave to add variation and make it look more like a natural environment.
Congrats, you now know how to add a bunch of fun details to your Terrain! If you’d rather do your modeling externally, you can still use your favorite 3D modeling program to create a cave mesh and import it using Unity’s DCC integration tools. Don’t forget to further decorate your cave with rocks or lighting!