1 Can I automate the removal of default textures/materials after importing 50+ 3D models (.glb, .fbx, .gltf) in Godot 4.4 which are already loaded and re import them?
2 how to automate the addition of already created one common textures/materials to all 50+ 3dmodels?
generate code for these
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Yes, you can automate both tasks in Godot 4.4 using GDScript and the EditorScript plugin. Since you're working with a large number of models and want to batch process them, you'll need to write a script that runs in the editor.
✅ 1. Automate Removal of Default Textures/Materials
When you import 3D models (like .glb, .fbx, .gltf), Godot generates default materials. You can remove or replace them programmatically.
✅ 2. Automate Applying a Common Material
You can load a predefined material (e.g., res://materials/CommonMaterial.tres) and assign it to all surfaces of all meshes in all models.
🧠 Requirements:
Godot 4.4
All models already imported
A common material saved as a .tres file
📁 File Structure Assumptions:
code
res://models/
res://materials/CommonMaterial.tres
💡 Editor Script (run in the Godot Editor)
Create a new script, e.g., BatchMaterialReplacer.gd, and run it from the Editor → Script Editor → Run.
gdscript
# BatchMaterialReplacer.gd
# Place this in your project and run it in the editor
extends EditorScript
const COMMON_MATERIAL_PATH = "res://materials/CommonMaterial.tres"
func _run():
var common_material = ResourceLoader.load(COMMON_MATERIAL_PATH)
if not common_material:
push_error("Common material not found at: " + COMMON_MATERIAL_PATH)
return
var model_dir = "res://models"
var dir_access = DirAccess.open(model_dir)
if not dir_access:
push_error("Directory not found: " + model_dir)
return
var files = dir_access.get_files()
for file_name in files:
if file_name.ends_with(".glb") or file_name.ends_with(".gltf") or file_name.ends_with(".fbx"):
var path = model_dir.path_join(file_name)
var resource = ResourceLoader.load(path)
if resource is Node:
var scene = resource.duplicate()
apply_common_material_to_scene(scene, common_material)
# Re-import or save modified scene
# Note: You can optionally save the modified scene to a new file
var new_path = path.replace(".", "_modified.")
ResourceSaver.save(scene, new_path)
print("Processed and saved: ", new_path)
func apply_common_material_to_scene(node, common_material):
if node is MeshInstance3D:
var mesh = node.mesh
if mesh:
for i in range(mesh.get_surface_count()):
mesh.surface_set_material(i, common_material)
for child in node.get_children():
apply_common_material_to_scene(child, common_material)
🛠️ How to Use:
Save your common material as CommonMaterial.tres in res://materials/
Place all your models in res://models/
Create a new script called BatchMaterialReplacer.gd
Paste the code above into it
In the Godot Editor → Open Script Editor → Select the script → Click "Run"
📝 Notes:
This script does not re-import the assets (re-importing requires modifying the import settings and re-triggering the import process). Instead, it loads the already imported scene, modifies it, and saves a new version with _modified suffix.
If you need to re-import assets from source (e.g., force reimport of .fbx files), you'd use ResourceImportMetadata and ImportPlugin APIs — which is more complex and usually not needed if you're just changing materials.
If you want to remove default materials entirely, you can set the surface material to null instead of replacing it.
❌ Optional: Remove Default Materials
Replace this line:
gdscript
mesh.surface_set_material(i, common_material)
With:
gdscript
mesh.surface_set_material(i, null)
🧪 Optional: Reimport Assets (Advanced)
To truly "reimport" and overwrite original files, you'd need to:
Modify the .import metadata files
Trigger reimport using ResourceLoader.reimport
This is more advanced and not always recommended unless you're certain about the import settings.
✅ Summary
Task
Supported?
Method
Remove default materials
✅
Loop over surfaces and set null
Replace with common material
✅
Load .tres, assign to surfaces
Automate for 50+ models
✅
Use EditorScript
Re-import assets
✅ (Advanced)
Modify .import files
Let me know if you'd like the reimport version or a file browser GUI for selecting folders.