Importing Blender files

Godot Version

Is it possible to make it so some blender objects get auto imported as Area3D and their colliders? I know it’s possible to import meshes are Area3D objects with advanced importing options, but I’d have to go through the meshes one by one.

On that note, why isn’t it possible to multi select objects in the advanced import settings?

I know that the import script is a thing, but I have no idea how it could do what I need it to. Judging by the documentation for it, I don’t think it’s really possible.

I suppose I could import the blend file, instance it as a scene, then run an editor script to turn objects into Area3D nodes, but, again, I guess this would have to be done manually, after every import. I’ll try to use EditorScenePostImport to do that automatically, but surely there’s a better way?

If you need a more advanced manipulation of the imported scene than what the Advanced import... dialog offers your only option is to use an EditorScenePostImport You can do whatever you want with that script. Add, remove, edit, reparent,… nodes

For example, a script that generates StaticBody3Ds for each MeshInstance3D it founds when importing the scene:

extends EditorScenePostImport

func _post_import(scene):
	return scene

func iterate(node):
	if node != null:
		if node is MeshInstance3D:
			# Create a static body
			var body =
			# Generate a convex collision shape from the mesh
			var shape =
			var collision_shape = node.mesh.create_convex_shape(true, true)
			shape.shape = collision_shape
			# Add the shape to the created static body
			body.add_child(shape, true)
			# Add the static body as a child of the node
			node.add_child(body, true)
			# Configure the collision layers and masks
			body.set_collision_layer_value(1, true)
			body.set_collision_mask_value(1, true)
			# Set the owner property of the body and shape to the node's owner
			body.owner = node.owner
			shape.owner = node.owner

			# Override the materials of the mesh with a custom material
			var mesh:Mesh = node.mesh
			for i in mesh.get_surface_count():
				mesh.surface_set_material(i, preload("res://assets/kaykit dungeon/dungeon_material.tres"))

		# Keep iterating
		for child in node.get_children():
1 Like

I don’t think there’s a design reason, it’s just that this hasn’t been implemented. There are no specific plans to implement this so far, but it’s technically feasible in a fashion similar to MultiNodeEdit in the inspector. It’s really difficult to get right though, so I wouldn’t expect it to happen soon.

Thank you for the reply, but that doesn’t seem to work. On the file I want to import, under import script I’ve got that script selected. I made it print some stuff so I know it is working correctly. However, after clicking reimport and I then go down to the file system, right click the .blend file, click New Inherited Scene and none of the nodes that were supposed to be added are there.
I guess I’m supposed to open the scene, or run that script from elsewhere but I don’t know how to do that.

It should work the way you did it. If you are using the exact same script then delete the part where I’m setting the custom material as you won’t have it and it won’t work.

1 Like

Thank you so much.

It worked. I had some older, non import scripted, versions of that scene running already, I closed those, restarted Godot, reapplied the import script, and it worked.

I really wish the documentation had an example of that code, the current docs made me think import scripts would change the properties and contents of the files themselves.