As you start developing on Voxel Play, chances are that you will need some additions or modifications to the asset. In order to keep your changes between versions of Voxel Play we recommend you to follow these practices:

Use Scriptable Objects

Voxel Play uses scriptable objects for many definitions (world, voxels, terrain and detail generators, items, etc.). ScriptableObjects are a great solution to serialize / save objects and link them. For example, if you want to add new fields to the ItemDefinition you can add custom fields to the existing scriptable object class, or create a new ItemDefinitionChild an inherit from the parent class. In addition to extending the class you can use the C# partial feature (see below).

Extending the functionality using C# partial keyword

Most Voxel Play classes are defined with the partial C# keyword. This means that you can create a new C# file using the same namespace and class name and add your own private fields and public properties and methods. They will automatically be merged with Voxel Play original class. For example, if you need to add a specific version of VoxelDestroy method, you can create this file:

namespace VoxelPlay {
public partial class VoxelPlayEnvironment : MonoBehaviour {

        public bool MyVoxelDestroy (VoxelChunk chunk, int voxelIndex) {

        ... your code goes here ...

Then, you will be able to call MyVoxelDestroy in the same way you call VoxelDestroy. The benefit from this approach is that your method can access all private fields from VoxelPlayEnvironment class and since your code resides in a different file you won't loose your changes when you upgrade Voxel Play (of course, make sure you place your own class files in a different folder than Voxel Play!)

Reacting to the events

Voxel Play provides many events which you can use to execute custom logic at certain moments. Following the example above, you could use the event OnVoxelDestroyed to execute additional FX effects, drop items, activate some game trigger, etc.

VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;
env.OnVoxelDestroyed += VoxelDestroyedEvent;
void VoxelDestroyedEvent(VoxelChunk chunk, int voxelIndex) {
    ... your code goes here ...

We encourage to use as many events as possible before modifying Voxel Play code, and alternatively use the partial class above to write variants to Voxel Play core functions.

Merging changes

if you have made changes to Voxel Play sources, it's recommended to import new versions in a second project first and then use a tool like WinMerge (Windows) or Beyond Compare (Mac) to compare your source code with the new update.