I’m currently working on a region loading system where when a player steps in to a region’s bounding box, only the parts contained within the bounding box are visible / interactable. The problem with my current approach is that it simply changes
Transparency: 1
CanCollide: false
Anchored: true
CanTouch: false
I’ve been told in the past that doing that makes the engine not render / handle the part, but in testing, there is no clear FPS increase when a large region is not visible. This system only handles BaseParts. My first approach was to parent the parts to a folder in Replicated First, however that yielded a very large and noticable lag spike when entering / exiting regions. Is there a proper way to un-render a BasePart without changing it’s parent?
This is my code:
RenderChunk Function
local RenderChunk = function()
local PartCount = Regions[Chunk] or 0
local Group = 0
if PartCount > 100 then
LoadStarted:Fire(PartCount)
end
for BasePart, Part in Parts do
if Character and BasePart:FindFirstAncestor(Character.Name) then
Parts[BasePart] = nil
end
if Part.Chunk == Chunk then
Part.Streamed = true
for Property, Value in Part.Properties do
BasePart[Property] = Value
end
else
Part.Streamed = false
BasePart.Transparency = 1
BasePart.CanCollide = false
BasePart.CanTouch = false
BasePart.Anchored = true
end
if PartCount > 100 then
Group += 1
if Group == 100 then
RunService.Stepped:Wait()
Group = 0
end
LoadPartDone:Fire()
end
end
LoadEnded:Fire()
end
Runs every RunService.Heartbeat
local OnHeartbeat = function()
if not Player.Character then return end
local InChunk = false
local TouchingParts = Workspace:GetPartBoundsInBox(Character:GetPivot(), Size, OverlapParameters)
for _, Part in TouchingParts do
if Regions[Part] then
InChunk = true
if Chunk ~= Part then
Chunk = Part
task.spawn(RenderChunk)
end
end
end
if not InChunk and Chunk then
Chunk = nil
task.spawn(RenderChunk)
end
end