Resizing Volume from code does not work correctly

0
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!

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

Hi!

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
volume.CreateChunks();

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

0
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 123 members have posted 454 times in 109 discussions