Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Region cannot be empty error when reading terrain voxels?

Asked by 7 years ago

I'm currently messing around with different Terrain methods.

However,when I try this script (taken from the wiki), I get an error saying 'Region cannot be empty' :

region=Region3.new(game.Workspace.A.Position,game.Workspace.B.Position)
region = region:ExpandToGrid(4)
local material, occupancy = game.Workspace.Terrain:ReadVoxels(region, 4)
local size = material.Size
for x = 1, size.X do
    for y = 1, size.Y do
        for z = 1, size.Z do
            print("Material at (", x, y, z, "): ", material[x][y][z])
            print("Occupancy at (", x, y, z, "): ", occupancy[x][y][z])
        end
    end
end

I have two parts in the workspace : "A" and "B" ; Both are at opposite corners of my terrain chunk.

yes,I have swapped the Vector3s when defining 'region', yet it still says "Region cannot be empty".

Any way to fix this?

1 answer

Log in to vote
3
Answered by 7 years ago
Edited 7 years ago

I had the same problem while using FillRegion. But there is a solution! I tested it on my own script and yours, and it works on both.

All you have to do is make sure that the x, y, and z coordinates in the first Vector3 are lower than the x, y, and z coordinates in the second Vector3. ALL three of them must be lower in value.

For example:

region = Region3.new(Vector3.new(1,1,1), Vector3.new(9,9,9))

As you can see, the first Vector3 coordinates are lower than the other ones on all three axes.

Just adjust your A and B positions so that A is lower than B on x, y, and z. You'll get an error if even one coordinate in the first Vector3 is greater than it's corresponding coordinate in the second Vector3. Hope this helps :)

Ad

Answer this question