Ive just finished Alex Stv's Voxel tutorial on http://alexstv.com/index.php/category/voxel-tutorial, and realized it would be very handy to have a custom inspector for the TerrainGenerator variables, so that I could easily tweak and test how the world would change by using it.

The problem is, the class doesn't actually implement MonoBehaviour, as it's always used by other classes. I could extend the class to MonoBehaviour, and that would allow me to use the inspector, but since this class only really governs how the height map are going to effect the position and type of the voxels, not the creation of the world itself, it would make the inspector less useful.

I wanted to be able to have a button in the inspector to regenerate the world, check the changes in a quick and efficient way. How would I go about to have an inspector that would both allow me to regulate and change the variables in TerrainGenerator, and also allow me to regenerate and (maybe) change some world variables?

Would I need to have multiple inspectors--one to change the variables used in the simplex, and another, smaller one for the regenerative button?


1 Answer 1


This can all be done within one inspector window, but requires two scripts to be made.

Create a TerrainGenerator : Monobehavior script that is attached to an empty game object. This is going to hold your chunk data in the form of a GameObject called root. You can make this a private variable or expose it publicly to manually set a root GameObject.

Next, create a TerrainGeneratorEditor : Editor class. This class will expose variables for width, height, noiseAmount, etc. This inspector will also present a button to generate the terrain. You would instantiate all the generator classes required inside the TerrainGeneratorEditor : Editor class. Chunk.cs, Block.cs, etc.

Now your generate button will do two things.

First is calling some type of Destroy() on your TerrainGenerator : Monobehavior script to kill your current batch of chunks attached to the root.

Then you generate new chunks and parent them to the root GameObject found inside your TerrainGenerator : Monobehavior script.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .