Loading MeshInstance3D from gltf during runtime

Godot Version

4.2.2

Question

I am trying to load a Mesh from a .glb file located on the end users file system. The file seems to be loading fine, as I can load the root of the glb as a Node3D (with one child) and then extract the child as a MeshInstance3D; however, when I try to change the mesh of my object it doesn’t change even though the object ID for the mesh is updated in the inspector.

The mesh displays fine if I add the root node to the scene.

Any tips would be greatly appreciated! Below is my code:

		var gltf_state = GLTFState.new()
		var gltf_doc = GLTFDocument.new()
		gltf_doc.append_from_file(new_mesh_path, gltf_state)
		var root_node = gltf_doc.generate_scene(gltf_state)
		var child: MeshInstance3D = root_node.get_child(0)
		self.mesh = child

You’ll need to use the MeshInstance3D.mesh property. Something like self.mesh = child.mesh

If that does not work then you may need to Resource.duplicate() it like self.mesh = child.mesh.duplicate()