Constantly changing Weld C0 is laggy? (updateGeometry lag)

I have a system where you can shoot out cars, and I have just recently converted it to just constantly change a SeatWeld C0 instead of setting HumanoidRootPart CFrame directly, because if I did the latter, the whole car would move because the SeatWeld is welded to the HumanoidRootPart and the seat, obviously, and the seat itself is welded to the car.

Anyway, I did some CFrame math to convert it and it works perfectly, but now it drops my FPS by about 20-35 frames.

This code is binded to render steps. I know the cause of the lag is because of the CFrame math, but why? This doesn’t look intense at all, and it’s not that different from the old code.

Old relevant code snippet (binded to RenderStep)

root.CFrame = CFrame.new(root.Position, root.Position + camera.CFrame.LookVector) * CFrame.Angles(0, 0, -math.rad(rotAngle))

New relevant code snippet (also binded to render step, this is what the old one was replaced by)

local origTarget = CFrame.new(root.Position, root.Position + camera.CFrame.LookVector) * CFrame.Angles(0, 0, -math.rad(rotAngle))
local targetRootCF = CFrame.new(c0.p, c0.p + camera.CFrame.LookVector) * CFrame.Angles(0, 0, -math.rad(rotAngle))
local rel = seat.CFrame * targetRootCF
				
seatWeld.C0 = targetRootCF * rel:ToObjectSpace(origTarget)
currentC0 = seatWeld.C0

Of course, staying still stops the lag. But when I look around, my FPS drops, and the MicroProfiler shows these firing up when my FPS starts dropping:

image

How do I fix this?

1 Like

There are a couple of threads lying around about updateGeometry. It comes down to the issue of you moving too many parts around at a given time and those parts are probably heavy in geometry, hence the label itself and how wide it’s spanning.

Consider checking out this Discussion thread for a bit more information:
https://devforum.roblox.com/t/whats-updateprepare-updateinvalidatedfastclusters-generatebatch-updategeometry/31176

One thing you can try is not updating in RenderStepped. You should typically never use RenderStepped if you aren’t updating the camera or something very, very small in the character (e.g. their transparency for zooming). Consider using Heartbeat instead so that your weld updates after physics simulation instead of before a frame renders. Stepped if physics are vital to your system and the weld needs to update before physics simulation starts.

2 Likes