Loading gltf/glb mesh from file system

Godot Version

4.2.2

Question

I have a node in my scene, and I want to switch out its mesh for the first mesh in a glb loaded from the file system. Currently my code looks like this:

		var gltf_state = GLTFState.new()
		var gltf_doc = GLTFDocument.new()
		gltf_doc.append_from_file(new_mesh_path, gltf_state)
		var new_mesh : ImporterMesh = gltf_state.get_meshes()[0].mesh
		self.mesh = new_mesh

Running it through the debugger it looks like the file is loading correctly and I can see that there is a mesh in the meshes array. To my understanding it seems like I can get the mesh into an ImporterMesh object which the docs say is analogous to ArrayMesh, however when I try to set the new mesh it doesn’t display.

AFAIK ImporterMesh is only available while importing a resource in the editor. It won’t work at runtime.

You can check how to load a 3D scene at runtime from a gltf file here Runtime file loading and saving — Godot Engine (stable) documentation in English I guess you can then use the normal Node API to access the MeshInstance3D node and get the Mesh from it.