How do I reference assets in GDscript?

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

Hello, I am generating a multimesh in code and would like to set the mesh of the multimesh to one of my mesh asset resources. I’m having trouble figuring out how to reference my assets.

This is my code for creating a multimesh, the problem is when setting multi_mesh.mesh. I get an error “multimesh->mesh.is_null()” is true. Any insight would help me, thank you!

func New_Multimesh():
	var multi_mesh_instance =
	var multi_mesh =
	multi_mesh.transform_format = MultiMesh.TRANSFORM_3D
	multi_mesh.instance_count = 100000
	multi_mesh.visible_instance_count = 10

	multi_mesh.mesh = preload("res://TreesFolder/Tree1Asset.glb")
	multi_mesh_instance.multimesh = multi_mesh
	return multi_mesh_instance
  1. double click tree1asset.glb
  2. select action and select set mesh save path
  3. set where to save, then select select current folder
  4. select all mesh and select set paths and select reimport
  5. change:


multi_mesh.mesh = preload("res://path_to_file_saved(above)")

megatron | 2023-03-13 22:16

Thank you so so much!!!

dizzy | 2023-03-13 22:32