EditableMesh doesn't work after the update

I have big problems with EditableMesh after the update, this piece of code worked before the update, and turned my meshpart into a plane, after the update it just stopped working, can someone explain what the problem is, preferably in more detail, because I don’t understand this topic at all.

local AssetService = game:GetService("AssetService")

local Water = script.Parent

local EditableMesh = AssetService:CreateEditableMesh()

local width = 100
local height = 100

local vertices = {}

for y = 1, height do

	local raw = {}

	for x = 1, width do

		local vertexPosition = Vector3.new(x - 1, 0, y - 1)
		local vertexId = EditableMesh:AddVertex(vertexPosition)

		raw[x] = vertexId
	end
	vertices[y] = raw
end
print("1 fors")
for y = 1, height - 1 do

	for x = 1, width - 1 do

		local vertex1 = vertices[y][x]
		local vertex2 = vertices[y + 1][x]
		local vertex3 = vertices[y][x + 1]
		local vertex4 = vertices[y + 1][x + 1]

		local triagle1 = EditableMesh:AddTriangle(vertex1, vertex2, vertex3)
		local triagle2 = EditableMesh:AddTriangle(vertex3, vertex4, vertex2)

	end
end
print("2 fors")

2nd attempt:

local AssetService = game:GetService("AssetService")
local myMeshPart = workspace:FindFirstChildWhichIsA("MeshPart")

local myEditableMesh

if myMeshPart then
    myEditableMesh = AssetService:CreateEditableMeshAsync(myMeshPart.MeshContent)
    if myEditableMesh then
        print("EditableMesh created.")
    else
        warn("Error.")
    end
else
    warn("MeshPart doesnt found.")
end

local function computeExtents(em: EditableMesh)
    local verts = em:GetVertices()
    if #verts == 0 then
        return Vector3.zero
    end
    local inf = math.huge
    local min = Vector3.new(inf, inf, inf)
    local max = Vector3.new(-inf, -inf, -inf)
    for _, id in verts do
        local v = em:GetPosition(id)
        min = min:Min(v)
        max = max:Max(v)
    end
    return max - min
end


local width = 100
local height = 100

local vertices = {}

for y = 1, height do
    local row = {}
    for x = 1, width do
        local vertexPosition = Vector3.new(x - 1, 0, y - 1)
        -- Используем myEditableMesh для добавления вершины
        local vertexId = myEditableMesh:AddVertex(vertexPosition)
        row[x] = vertexId
    end
    vertices[y] = row
end
print("1 fors")

for y = 1, height - 1 do
    for x = 1, width - 1 do
        local vertex1 = vertices[y][x]
        local vertex2 = vertices[y + 1][x]
        local vertex3 = vertices[y][x + 1]
        local vertex4 = vertices[y + 1][x + 1]

        myEditableMesh:AddTriangle(vertex1, vertex2, vertex3)
        myEditableMesh:AddTriangle(vertex3, vertex4, vertex2)
    end
end
print("2 fors")

ive tried the same thing and for some reason it doesnt work either

I believe that you have to run :CreateMeshAsync() on the editable mesh that was created, then run ApplyMesh on your mesh to actually change it. Check the post here.

1 Like

Should I do all these actions on MeshPart or what? Instance.new(“EditableMesh”) gives "Unable to create an Instance of type “EditableMesh” error. I don’t quite understand, could you give me an algorithm of my actions please?

You can no longer create EditableMeshes. Check the link I sent there is sample code you can copy.

Okay I managed to add EditableMesh but now I have an error with adding vertex:
local vertexId = myEditableMesh:AddVertex(vertexPosition)
Such lines make the following error appear: EditableMesh is fixed-size, adding or removing elements is not allowed in-experience.
Maybe I should enable some setting other than EditableMesh, or the problem is in the code?