Godot Version
4.1.3
Question
I’m going crazy here. I’m trying to create a basic importer plugin. My _import
method, I’ve literally just copy-and-pasted an example from the Godot docs to create a MeshInstance3D
and try and save it to disk, but even that doesn’t work. I just get the following error:
Can’t save empty resource to path ‘res://.godot/imported/RING1.TMD-018865a4c2cb32f2b980cb8ca348885a.mesh’.
My _import
method:
func _import(source_file: String, save_path: String, options: Dictionary, platform_variants: Array[String], gen_files: Array[String]) -> Error:
var file = FileAccess.open(source_file, FileAccess.READ)
if file == null:
return FileAccess.get_open_error()
# TODO: Parse actual file
var vertices = PackedVector3Array()
vertices.push_back(Vector3(0, 1, 0))
vertices.push_back(Vector3(1, 0, 0))
vertices.push_back(Vector3(0, 0, 1))
var arr_mesh = ArrayMesh.new()
var arrays = []
arrays.resize(Mesh.ARRAY_MAX)
arrays[Mesh.ARRAY_VERTEX] = vertices
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
var mesh_instance = MeshInstance3D.new()
mesh_instance.mesh = arr_mesh
return ResourceSaver.save(mesh_instance, "%s.%s" % [save_path, _get_save_extension()])
Can any one see where I might be going wrong? Why is going saying the resource is “empty” when I’m creating a MeshInstance3D
, and setting its mesh
property to an ArrayMesh
instance that has three vertices?