So my game uses custom characters, and I’ve been redoing it with CSG (about 25 unions).
It has a ridiculous game pass that lets the owner set their character’s height to any value they want.
Whenever I set a character’s scale to something above 100x, the game freezes up.
So the game lags when a union’s size is set to something really big. I assume it’s doing something physics related (I only really need the mesh data in my case)
Repro:
-- Put a somewhat complex union named "Union" in the workspace, run this:
local function Rescale(union, scale)
local originalCFrame = union.CFrame -- Just to keep the part in one place
union.Size = union.Size * scale -- Cause of lag!
union.CFrame = originalCFrame
end
local union = workspace.Union
-- Disable physics, repro works with or without
union.CanCollide = false
union.Anchored = true
wait(2)
print("Prepare for lag")
wait(1)
Rescale(union, 10000)
That sort of makes sense - you’re adjusting every component of the solid model you have there. CSG isn’t instant, and it takes longer the larger the components are.
Roblox Collision Detection subdivides the areas into very specific sections to filter unnecessary collision detection. This information is updated on the fly. When you increase an object’s scale to 10,000 you are suddenly putting the same object into thousands of little spacial regions that all now have to keep track of it. Try the same operation with a single part and you will see similar lag.
This is a serious problem for my game. I’ve been trying to optimize recently, and most of my lag can be traced back to setting part sizes for character height scaling.
The parts in my case are purely graphical and serve no purpose as a physical object; I only need the mesh!
Simply setting a character’s scale to something like 1.5x causes a delay over 100ms long as it sets the size of 30 unions. When I remove the line of code that sets part sizes, it is less than 1ms. My earlier character rigs never had this problem, because it would set mesh scales instead of part sizes; I could even lerp a character’s height at 60 FPS.
Some possible solutions for my case:
Ability to disable a part’s physics completely
Ability to upload meshes
Ability to convert a union to a mesh
Optimize something somewhere?