Required virtual method must be overridden before calling method when setting mesh on Godot 4

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By anthony63

Hello, i am trying to set a mesh to a MeshInstance3D on godot 4.0 but it is giving this error

_ready: Required virtual method Mesh::_get_surface_count must be overridden before calling. <C++ Source> scene/resources/mesh.h:62 @ _gdvirtual__get_surface_count_call() _ready: Required virtual method Mesh::_get_blend_shape_count must be overridden before calling. <C++ Source> scene/resources/mesh.h:72 @ _gdvirtual__get_blend_shape_count_call() _ready: Condition "!static_body" is true. <C++ Source> scene/3d/mesh_instance_3d.cpp:241 @ create_trimesh_collision()
This is the source code

func update():
	if mesh_instance != null:
		mesh_instance.call_deferred("queue_free")
		mesh_instance = null
		
	mesh = Mesh.new()
	mesh_instance = MeshInstance3D.new()
	
	st.begin(Mesh.PRIMITIVE_TRIANGLES)
	for x in Globals.CHUNK_SIZE.x:
		for y in Globals.CHUNK_SIZE.y:
			for z in Globals.CHUNK_SIZE.z:
				create_block(x, y, z)
	
	st.generate_normals(false)
	st.set_material(material)
	st.commit(mesh)
	
	mesh_instance.set_mesh(mesh)
	add_child(mesh_instance)
	mesh_instance.create_trimesh_collision()
:bust_in_silhouette: Reply From: Wakatta
mesh = ArrayMesh.new()

Expanding/clarifying a little bit about this, instead of using mesh = Mesh.new(), use mesh = ArrayMesh.new()

ibito | 2022-12-29 01:32