Programming Guide

advanced scripting

Voxel Play 3 · Scripting / API

Tip: Check the demo scene scripts included with Voxel Play 3 for runtime usage examples.

Getting Started

Voxel Play 3 exposes its public API through the VoxelPlayEnvironment class (singleton). All methods and properties documented in this section belong to VoxelPlayEnvironment unless otherwise noted.

using VoxelPlay;

// Get the singleton instance
VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;

// Place a voxel
VoxelDefinition stone = env.GetVoxelDefinition("Stone");
env.VoxelPlace(new Vector3d(0, 10, 0), stone);

// Subscribe to events
env.OnVoxelDestroyed += (chunk, voxelIndex) => {
    Debug.Log("Voxel destroyed!");
};

Namespace

All Voxel Play types live under the VoxelPlay namespace. Add using VoxelPlay; at the top of your scripts.

Key Types

class VoxelPlayEnvironment

Main API singleton. Access via VoxelPlayEnvironment.instance. All world, voxel, terrain, item, model, and event APIs are accessed through this class.

struct Vector3d

Double-precision 3D vector used for world positions. Supports large worlds without floating-point precision issues.

struct Voxel

Represents a single voxel with its type, color, light, and metadata.

struct VoxelIndex

References a specific voxel within a chunk (contains chunk reference + voxel array index).

struct VoxelHitInfo

Contains raycast hit data: chunk, voxel index, hit point, normal, and distance.

class VoxelChunk

Represents a 16×16×16 chunk of voxels. Contains voxel data, mesh, lighting, and colliders.

class VoxelDefinition

Scriptable object defining a voxel type (textures, sounds, resistance, rendering mode, etc.).

class ModelDefinition

Scriptable object representing a 3D voxel model that can be placed in the world.

class ItemDefinition

Scriptable object defining an item (tool, weapon, block) with its properties and category.

class BiomeDefinition

Scriptable object defining a biome with its terrain rules, vegetation, and voxel types.

class VoxelPlaceholder

MonoBehavior attached to custom voxel GameObjects. Allows per-voxel scripting.

Enums

enum ChunkModifiedFilter { Anyone, OnlyModified, NonModified }

Filter for chunk queries. OnlyModified returns chunks changed by the player; NonModified returns untouched chunks.

enum ColliderTypes

Filter for collider detection in raycasts and voxel queries.

enum HideStyle

Controls how hidden voxels are rendered (fully invisible, semi-transparent, etc.).

enum ItemCategory

Categorizes items (voxel, tool, torch, weapon, general).

Delegates

delegate float SDF(Vector3d position)

Signed Distance Function delegate used for custom volume definitions when querying voxels in arbitrary shapes.

API Sub-Pages

Due to the extensive API (~177 public methods), the documentation is organized into functional areas:

  • World & Chunk Management — World operations, chunk access, visibility, and redraw
  • Voxel Operations — Placement, destruction, damage, and collapse
  • Voxel Queries — Index lookups, position calculations, and spatial queries
  • Voxel Properties — Color, rotation, visibility, custom properties, highlighting, and physics
  • Environment & Terrain — Raycasting, terrain height, biomes, water, lighting, and time
  • Items & Models — Item spawning, torches, model placement, and UI messaging
  • Events — All event callbacks for voxels, chunks, environment, and models
Was this page helpful?