Updating EditableMesh results in either very laggy mesh or client

I was trying to make smooth ocean waves with EditableMeshes but it seems like the performance after the recent Mesh API update has went down significantly. I used the example in the update post but when creating a new mesh to use in :ApplyMesh(), it takes 0.03 seconds at the most which is too slow for real-time wave simulation.

I was looking around the posts but :ApplyMesh() seems to be the only option, which is kind of disappointing because it does not apply updates to the editable mesh automatically.

os.clock()

Screenshot 2024-11-01 at 8.35.30 AM

Script

*Ignore print and clock, those are just for testing

local TweenAccuracy = 60

local function TweenVerts(Mesh, EditableMesh, Speed, TweenTable)
	local Count = 0
	repeat
		task.spawn(function()
			local clock1 = os.clock()
			for i,v in pairs(TweenTable) do
				local VertexId = v[1]
				local OldPos: Vector3 = v[2]
				local NewPos: Vector3 = v[3]
				local SetPos = OldPos:Lerp(NewPos, 1 / TweenAccuracy)
				OldPos = SetPos

				EditableMesh:SetPosition(VertexId, SetPos)
			end
			local clock2 = os.clock()
			print("ApplyPosition: " .. clock2 - clock1)
			local clock3 = os.clock()
			local newMeshPart = EditableMesh:CreateMeshPartAsync(Vector3.new(1, 1, 1))
			local clock4 = os.clock()
			print("NewMeshPart: " .. clock4 - clock3)
			local clock5 = os.clock()
			Mesh:ApplyMesh(newMeshPart)
			local clock6 = os.clock()
			print("ApplyMesh: " .. clock6 - clock5)
		end)
		task.wait(Speed / TweenAccuracy)
		Count += 1
	until Count == TweenAccuracy
end

If theres any other way of applying editable meshes without having to create a new mesh each time I want to update an existing mesh let me know. Any help is appreciated!

Fixed it, seems like using ApplyMesh shouldn’t be used. Use the mesh created by EditableMesh:CreateMeshPartAsync() instead

note that it won’t have proper collision

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.