My Pet System Uses A Lot Of Memory

Whenever I run my rendering function for my pet system, it uses A LOT of memory. To put it into perspective, it uses more memory that the constant raycast I cast to the floor to make the pet’s CFrame relative.

Here you can see the total ms measured for just that function. Apparently PivotTo uses A LOT of memory.

Here is the function:

local function MoveTowards(pet, targetCFrame, speed, minDistance, maxDistance, lerpAlpha, deltaTime)
	local PetPivot = pet:GetPivot()
	if not PetPivot then return end
	local distance = math.clamp((targetCFrame.Position - PetPivot.Position).Magnitude, 0, maxDistance)
	
	local alpha = math.clamp(lerpAlpha * distance, 0, 1)
	pet:PivotTo(PetPivot:Lerp(limitCFrameY(targetCFrame,minY,maxY), alpha))
end
3 Likes

It’s fine, don’t worry about it unless your users complain about memory usage.

1 Like

how do the pets work? Are they constantly being moved in some sort of a loop?

1 Like

For sure, lowering memory usage is never good

It is inside of a renderstepped with a 30 fps cap

Are the pets just part of the character for visuals? For example, they just follow the player or something?

It’s like pet simulator, so yes they follow the player

then you can use align position and align orientation if its just purely for visuals.

How will that solve the problem?

you can attach the pet onto the player so it will follow the player instead of you having to loop this.

The loop is the cause for high memory right?

If I attach the pet onto the player aka welding it. It will visually look terrible

how so…? [char limit]]]]]]]]]]]]]

They will always be relative to the character to a fixed position and it wont make them feel alive, games only do this if they have a racing mechanic where the character have to go really fast and CFraming it wont work as the character is too fast. That is not the case here

ahh okay. Lemme try something and see if its what you wanted or not. I’m having a hard time understanding it.

The main concern is that PivotTo uses a lot of memory as shown in the first post.

ohh i understand how you meant, you want kinda like animations for the pet.

Unfortunately, I have no clue xd. Like nicemike40 said, I would look at the complains from the users and also just make it purely client sided.

I don’t think the memory being used is enough to directly lag them on let’s say an average modern device, so they wont really complain. The problem is that the resources that are being used are too much memory for that one task. It is very concerning that just that pivotto function uses 20% of the entire client’s memory. Also the entire system is on client.
image

Okay I just did a quick test in studio pivoting and lerping a giant model, but my memory usage was still very low, so I have no clue why yours is so high. Although my script activity on the other hand was very high.

Roblox does so much nonsense under the hood—you have no way to actually control your memory usage at a fine grained level. I just mean that it’s not worth it to stress over the effect of five lines of code. Does it do the thing you want it to do without crashing? Great, done, go implement the next feature.

1 Like