Resizing Volume from code does not work correctly

Siedge posted this 06 February 2016

I instantiate a Volume Prefab and then in my code I have

        volume.YChunkSize = 7;
        volume.XChunkSize = 4;
        volume.ZChunkSize = 1;
        volume.XSize = 4;
        volume.YSize = 7;
        volume.ZSize = 1;

This changes the setting of the Volume but the frame does not change. Also changing the frames size directly doesn't help. Nor Deleting the Frame.

Thanks in advance for the help!

Order By: Standard | Newest | Votes
GarethIW posted this 06 February 2016


I probably need to provide some easy methods for creating volumes at runtime in future, but for now there's a little more work you have to do.

Continuing on from the correct code you already have, you'll need to do something like the following:

// Set the size on the frame
var frame = volume.GetCurrentFrame();
frame.XSize = volume.XSize;
frame.YSize = volume.YSize;
frame.ZSize = volume.ZSize;
// Resize the voxel array
frame.Voxels = new Voxel[frame.XSize*frame.YSize*frame.ZSize];
// Recreate all chunks

Note that this will clear all voxels in the volume. Also, I haven't actually tested this, it's off the top of my head.

You can take a look at EditorResizeWindow.cs to see how resizing works in the editor.

Let me know if you need more help!

Last edited 14 February 2016

Siedge posted this 06 February 2016

Worked perfectly (Well besides CreateAllChunks is CreateChunks but I understood what you meant)

Again thank you for the help!

Our 127 members have posted 466 times in 112 discussions