How to load terrain in chunks

I have a TerrainRegion object and I’m trying to load terrain using this plugin/module.

The module provided by the plugin direclty pastes the TerrainRegion object given:

local position = Vector3int16.new(
	-math.floor(terrainRegion.SizeInCells.X / 2),
	-math.floor(terrainRegion.SizeInCells.Y / 2),
	-math.floor(terrainRegion.SizeInCells.Z / 2)
)
	
workspace.Terrain:PasteRegion(terrainRegion, position, true)

The problem with this is that I keep running into script timeouts with large maps. I’ve tried using ChatGPT, scoured YouTube and DevForum, but I could only find this script that doesn’t work for me.

I have no experience in terrain loading/generation, so I don’t know how to split terrain into chunks of TerrainRegions. Does anyone know how to, or does anyone have any open-source scripts available that I can use?

2 Likes

There is a plugin called Infinite Terrain. The chunk map works more or less but falls short when it comes to returning to your original location if you move too far away. I have spent a lot of time rebuilding it. However, it can be a great resource for learning how to implement this…

Endless landscape
My progress so far.

1 Like

Thanks, but I have another question. What is the second parameter of terrain:PasteRegion? I’m very confused by it, because whenever I try to import terrain without the position variable I put above (I try to set the “corner” myself), the terrain never generates. I tried looking at the documentation, but it doesn’t tell me what corner does.

1 Like

Your scripts are timing out when loading terrain?
It’s most performant to load the entire terrain at once rather than in chunks.

Im pretty sure something else is wrong, altough i could be wrong
Can you try workspace.Terrain:PasteRegion(region, workspace.Terrain.MaxExtents.Max, true)

1 Like

The corner position. If you don’t use a meaningful corner position, the terrain might not appear because it could be placed far from your expected area or in an invalid location. Something like this.

local terrain = workspace.Terrain
terrain:FillBlock(CFrame.new(0, 5, 0), Vector3.new(16, 16, 16), Enum.Material.Grass)
local region = Region3int16.new(Vector3int16.new(-8, 0, -8), Vector3int16.new(8, 16, 8))
local copiedRegion = terrain:CopyRegion(region)
local corner = Vector3int16.new(50, 10, 50)
terrain:PasteRegion(copiedRegion, corner, true)
1 Like

This guy really break all this stuff down well: okeanskiy

1 Like