Voxel Operations

advanced scripting

Voxel Play 3 · Scripting / API

Class: All members on this page belong to VoxelPlayEnvironment. Access via VoxelPlayEnvironment.instance.

Voxel Placement

void VoxelPlace(Vector3d position, VoxelDefinition voxelType, bool playSound = false, bool refresh = true)

Places a voxel of the given type at the specified world position.

position
World position (snapped to voxel grid).
voxelType
The voxel definition to place.
playSound
Play the placement sound effect.
refresh
Immediately refresh the chunk mesh. Set to false when placing many voxels in a batch, then call ChunkRedrawAll().
void VoxelPlace(Vector3d position, VoxelDefinition voxelType, Color tintColor, bool playSound = false, bool refresh = true)

Places a voxel with a custom tint color.

void VoxelPlace(Vector3d position, Color tintColor, bool playSound = false, bool refresh = true)

Places a voxel using the default type with the specified tint color.

void VoxelPlace(VoxelChunk chunk, int voxelIndex, Color tintColor, bool playSound = false, bool refresh = true)

Places a voxel directly in a chunk by voxel index.

void VoxelPlace(Vector3d position, Voxel voxel, bool playSound = false, bool refresh = true)

Places a complete Voxel struct (preserving all its properties).

void VoxelPlace(Vector3d position, VoxelDefinition voxelType, bool playSound, Color tintColor, float amount = 1f, int rotation = 0, bool refresh = true)

Places a voxel with full control over tint, fill amount, and rotation.

amount
Fill level (0-1). Used for water or partial voxels.
rotation
Texture rotation index.

Batch Placement

void VoxelPlace(List<Vector3d> positions, VoxelDefinition voxelType, Color32 tintColor, List<VoxelChunk> modifiedChunks = null)

Places voxels at multiple positions in one call. Optionally returns the list of modified chunks.

void VoxelPlace(List<VoxelIndex> indices, VoxelDefinition voxelType, Color tintColor, List<VoxelChunk> modifiedChunks = null)

Places voxels at specific chunk indices. Efficient for pre-computed positions.

void VoxelPlace(Vector3d boxMin, Vector3d boxMax, VoxelDefinition voxelType, List<VoxelChunk> modifiedChunks = null)

Fills a box volume with voxels of the given type.

void VoxelPlace(Vector3d boxMin, Vector3d boxMax, VoxelDefinition voxelType, Color tintColor, List<VoxelChunk> modifiedChunks = null)

Fills a box volume with tinted voxels.

void VoxelPlace(Vector3d boxMin, Vector3d boxMax, Voxel[,,] voxels, bool ignoreEmptyVoxels = false)

Places a 3D array of voxels into a volume region.

void VoxelPlace(VoxelChunk chunk, List<ModelBit> voxels)

Places voxels from model bit data directly into a chunk.

bool VoxelOverlaps(Vector3d position, VoxelDefinition type, Quaternion rotation, int layerMask = -1)

Checks whether placing a voxel at the given position would overlap with existing colliders. Useful for placement validation.

Voxel Destruction

bool VoxelDestroy(Vector3d position, bool createChunkIfNotExists = false)

Destroys the voxel at the specified world position. Returns true if a voxel was destroyed.

bool VoxelDestroy(VoxelChunk chunk, int voxelIndex)

Destroys a voxel by its chunk reference and index.

Voxel Damage

bool VoxelDamage(Vector3d position, int damage, bool playSound = false)

Applies damage to the voxel at the given position. The voxel is destroyed when damage exceeds its resistance. Returns true if the voxel was destroyed.

bool VoxelDamage(Vector3d position, Vector3 hitDirection, int damage, bool addParticles = false, bool playSound = false)

Applies directional damage with optional particle effects.

bool VoxelDamage(Vector3d voxelPosition, Vector3d hitPoint, Vector3 normal, int damage, bool addParticles = false, bool playSound = false)

Applies damage with precise surface hit information for accurate particle spawning.

bool VoxelDamage(VoxelHitInfo hitInfo, int damage, bool addParticles = false, bool playSound = false)

Applies damage using a VoxelHitInfo struct (typically from a raycast).

bool VoxelDamage(VoxelHitInfo hitInfo, int damage, bool addParticles = false, bool playSound = false, bool showDamageCracks = true, bool canAddRecoverableVoxel = true)

Full damage with control over visual cracks and recoverable voxel spawning.

showDamageCracks
Show crack overlay texture as the voxel takes damage.
canAddRecoverableVoxel
Allow the destroyed voxel to drop a recoverable item.

Area Damage

int VoxelDamage(Vector3d origin, int damage, int radius, bool attenuateDamageWithDistance, bool addParticles, bool playSound = false, bool showDamageCracks = false, bool canAddRecoverableVoxel = true)

Applies damage to all voxels within a radius. Returns the number of voxels destroyed. Useful for explosions.

radius
Blast radius in voxel units.
attenuateDamageWithDistance
Reduce damage for voxels farther from the origin.
int VoxelDamage(Vector3d origin, int damage, int radius, bool attenuateDamageWithDistance, bool addParticles, List<VoxelIndex> damagedVoxels, bool playSound = false, bool canAddRecoverableVoxel = true)

Area damage that also returns a list of all damaged voxel indices for post-processing.

Voxel Collapse

void VoxelCollapse(Vector3d position, int amount, List<VoxelIndex> voxelIndices = null, float consolidateDelay = 0)

Makes voxels above the given position fall/collapse. Simulates gravity for unsupported voxels.

amount
Number of voxels above to collapse.
voxelIndices
Optional output list of collapsed voxel indices.
consolidateDelay
Delay in seconds before fallen voxels settle into the grid.

Voxel Resistance

int GetVoxelResistancePoints(Vector3d position)

Returns the remaining resistance (durability) points of the voxel at the given position.

int GetVoxelResistancePoints(VoxelChunk chunk, int voxelIndex)

Returns the resistance points of a voxel by chunk reference.

Code Example

using VoxelPlay;

public class VoxelBuilder : MonoBehaviour
{
    void BuildWall()
    {
        var env = VoxelPlayEnvironment.instance;
        VoxelDefinition brick = env.GetVoxelDefinition("Brick");

        // Build a 10x5 wall
        for (int x = 0; x < 10; x++)
        {
            for (int y = 0; y < 5; y++)
            {
                env.VoxelPlace(
                    new Vector3d(x, y, 0),
                    brick,
                    playSound: false,
                    refresh: false  // defer mesh rebuild
                );
            }
        }

        // Refresh all chunks at once
        env.ChunkRedrawAll();
    }

    void Explode(Vector3d center)
    {
        var env = VoxelPlayEnvironment.instance;
        int destroyed = env.VoxelDamage(
            center,
            damage: 100,
            radius: 5,
            attenuateDamageWithDistance: true,
            addParticles: true,
            playSound: true
        );
        Debug.Log($"Destroyed {destroyed} voxels!");
    }
}
Was this page helpful?