Basically, I made a chunk based terrain generation system.
And this happens whenever the chunk is unloaded:
Do you guys happen to know what I could do to fix this?
I just make the region that generates air to remove chunks slightly bigger than the region used to generate chunks and that works well.
I also do that but the issue is that it leaves this teeny tiny gap when generated back
local function Load()
if TerrainData then
local Corner1_16 = Vector3int16.new(math.floor(Corner1Int16.X / 4),math.floor(Corner1Int16.Y / 4),math.floor(Corner1Int16.Z / 4))
Terrain:PasteRegion(TerrainData, Corner1_16, true)
else
for X = ChunkX, ChunkX + ChunkSize do
for Z = ChunkZ, ChunkZ + ChunkSize do
Counter += 1
local Height = GetHeight(X, Z) * Amplitude
local Material = Enum.Material.Water
for i,v in Materials do
if Height <= v[1] then
Material = v[2] break
end
end
local PosX, PosZ = X * Radius, Z * Radius
local FinalPos = Vector3.new(Radius * X, Height + BaseHeight, Radius * Z)
local Reg = Region3.new(
Vector3.new(FinalPos.X-0.5, WaterLevel - ((Amplitude / 2) - (WaterLevel - BaseHeight)), FinalPos.Z-0.5),
Vector3.new(FinalPos.X+0.5, WaterLevel, FinalPos.Z+0.5)
):ExpandToGrid(4)
Terrain:FillRegion(Reg, 4, Enum.Material.Water)
Terrain:FillBall(FinalPos, Radius, Material)
if X % Radius == 0 and Z % Radius == 0 then
local RandomChance = Random.new(math.floor(Seed * (10 ^ 8)) + Counter):NextNumber()
if table.find(TreeGenRequirement.Materials, Material) and TreeGenRequirement.RandomChance >= RandomChance then
local Tree:Model = Trees[math.random(#Trees)]:Clone()
local Center, Size = Tree:GetBoundingBox()
Tree.Parent = TreeFolder
Tree:PivotTo(CFrame.new(
Vector3.new( FinalPos.X, FinalPos.Y + (Size.Y / 1.75), FinalPos.Z ) + Vector3.new(math.random(-10,10)/5,0,math.random(-10,10)/5)
) * CFrame.Angles( math.random() / 32, math.random() * 2, math.random() / 32 )
)
end
end
end
end
local Corner1_16 = Vector3int16.new(math.floor(Corner1Int16.X / 4),math.floor(Corner1Int16.Y / 4),math.floor(Corner1Int16.Z / 4))
local Corner2_16 = Vector3int16.new(math.floor(Corner2Int16.X / 4),math.floor(Corner2Int16.Y / 4),math.floor(Corner2Int16.Z / 4))
TerrainData = Terrain:CopyRegion(Region3int16.new( Corner1_16, Corner2_16 ))
end
CachedData.Structures.Parent = ChunksFolder
end
local function Unload()
if not TerrainData then warn("Terrain is not cached, loading it again will generate it.") end
CachedData.Structures.Parent = script.UnloadedChunks
Terrain:FillRegion(Region3.new(Corner1 - Vector3.new(Radius,0,Radius), Corner2 + Vector3.new(Radius,0,Radius)):ExpandToGrid(4), 4, Enum.Material.Air )
end
You could try having it check if the chunks immediately next to the now unloaded chunk is empty or not loaded, and if so, set the regions in those chunks to air as well, which should fix your problem (this issue might also indicate that there is a problem with how your generator is positioning the terrain voxels it creates as well, which might be something to look into)