Godot Version
4.4, Windows 11
Question
Hello! I am having a weird issue when generating a terrain using SurfaceTool and MeshInstance3D, and when I try to apply collisions to it, I get this error:
ERROR: servers\rendering_server.cpp:1193 - Condition “array_len == 0” is true. Returning: ERR_INVALID_DATA
ERROR: scene\resources\mesh.cpp:1810 - Condition “err != OK” is true.
When I print the Vertex Array, I can see data, and actually I can see the Mesh being rendered perfectly without errors, even normals are working fine, and I have a shader applying textures based on normals, vertex Y position, and UV. Sadly, when I add a StaticBody3D, with its CollisionShape (either convex or concave), I get the error from above. I checked the Godot Source code for those errors (rendering server: 1193, and mesh: 1810), and apparently, it means that the vertex array has no data.
Also, when I print the Vertex Arra,y I get data (this is a smaller mesh, but still gets the error):
I even went to the tscn file, looked up for the surface 0, and found the vertex array:
I am not sure If I am missing any part while generating the mesh that the CollisionShape3D expects to read the vertex array, but for the rendering server this mesh is empty.
Here is my code for that piece:
func update_vertex_height(plane: PlaneMesh) -> ArrayMesh:
var plane_arrays := plane.get_mesh_arrays()
var vertex_array: PackedVector3Array = plane_arrays[ArrayMesh.ARRAY_VERTEX]
var uv_array: PackedVector2Array = plane_arrays[ArrayMesh.ARRAY_TEX_UV]
var index_array: PackedInt32Array = plane_arrays[ArrayMesh.ARRAY_INDEX]
var st := SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
for i in index_array.size():
var idx = index_array[i]
var vertex := vertex_array[idx]
var uv := uv_array[idx]
var normal := Vector3.UP
var tangent := Vector3.RIGHT
if texture:
vertex.y = get_vertex_height(idx)
normal = get_normal(idx)
tangent = normal.cross(Vector3.UP).normalized()
var t4 := Plane(tangent.x, tangent.y, tangent.z, 1.0)
st.set_normal(normal)
st.set_uv(uv)
st.set_tangent(t4)
st.add_vertex(vertex)
st.generate_tangents()
# Set indices if the PlaneMesh is indexed
if index_array.size() > 0:
st.index()
var mesh := st.commit()
return mesh
Many thanks in advance if anyone knows the solution to my problem