
The HeightmapVoxels component allows you to create voxel-based terrain using a heightmap and a colormap texture. This is useful for creating large ground surfaces that support voxel destruction and physics.
Create GameObject: Create a new empty GameObject in your scene.
Add Component: Add the HeightmapVoxels component to the GameObject.
Prepare Textures:
Assign Textures: Drag your textures into the Heightmap and Colormap fields of the component.
Configure Settings: Adjust the Tile Size, Height Scale, and other parameters as needed.
Play: The terrain is generated automatically when the game starts (in the Start() method).
| Parameter | Description | Default |
|---|---|---|
| Heightmap | Grayscale texture defining terrain height. White is high, black is low. | None |
| Colormap | Texture defining the color of the terrain surface. | None |
| Forbid Mask | Optional mask texture. | None |
| Tile Size | Size of chunks to split the generation into. Smaller tiles may help with memory but increase object count. | 256 |
| Height Scale | Multiplier for the vertical height of the terrain. | 1 |
| Voxel Size | Size of individual voxels in world units. Smaller values = more detail but heavier performance. | 0.25 |
| Lod Bias | Level of Detail bias for the mesh generation. | 1.0 |
| Voxel ID | The material type of the generated voxels (e.g., Stone, Dirt, Grass). Affects sound and physics. |
Stone |
| Indestructible | If enabled, the terrain cannot be destroyed by weapons or explosions. | true |
Heightmap textures can take time to generate. The script splits them into tiles to manage this.PxVoxelColliderGenerator for physics collisions.Indestructible is disabled, the ground can be dug into or destroyed like other voxel objects.1. Voxel Count and Texture Resolution The number of voxels along the X and Z axes (the voxel grid resolution) is directly determined by the pixel resolution of your Heightmap texture.
Pixel Width * Voxel Size.2. Recommended Size Keep it under 256x256. It is strongly recommended to ensure your Heightmap texture is smaller than 256 pixels on each side.
Voxel Size parameter instead of increasing the texture resolution, or use multiple smaller HeightmapVoxel objects.