Godot Version
4.7
Question
Goal
I’m importing my assets into godot, the downloaded assets have many useless nodes, I want to get rid of them
I can’t change the asset structures in blender, it will take too much time since I have many assets
My solution
I created a script to delete those nodes, this is the script, it deletes the parent of all the nodes with a parent, the only node I need (the mesh instance 3d) doesn’t have a child
@tool
extends EditorScenePostImport
func _post_import(scene: Node) -> Object:
var node = scene
while node.get_child_count(true) > 0:
node = delete_node_parent(node)
return node
func delete_node_parent(node: Node) -> Node:
var child = node.get_child(0)
node.remove_child(child)
child.owner = null
set_children_owner(child, child)
return child
func set_children_owner(node, owner):
for n in node.get_children():
n.owner = owner
set_children_owner(n, owner)
I put that script in the import settings of the assets I want to modify
this code seems to work because it removes all the useless nodes, this is the result in the editor
Issue
the main issue is when I import the asset running the import script, the asset becomes EXTREMELY big for no reason (I’m not changing the root scale)
in comparison, this is the same asset imported without running the import script (normal dimension)
can someone help me to understand how to fix my code and import the assets correctly?
-
-
-
Another solution
I created another import script using a different approach: it selects the last child (the mesh instance 3d) that I want to keep and replace the scene with only that node (the _post_import return the scene that will be saved in the asset)
@tool
extends EditorScenePostImport
const OBJECT_SCALE: float = 8
func _post_import(scene: Node) -> Object:
var last_child: Node = get_last_child(scene)
if last_child is MeshInstance3D:
return last_child
push_error("scene doesn't contain a mesh")
return scene
func get_last_child(node: Node) -> Node:
while node.get_child_count() > 0:
if node.get_child(0):
node = node.get_child(0)
else:
push_error("node doesn't have a child")
break
return node
Issue
the code kinda works, it removes the nodes I don’t want to keep, but it still makes the asset so big
on top of that, this code throws 2 errors that I don’t understand, with some attempts I found out that `node.get_child(0)` causes code causes the error
can someone explain me why and give me a solution?





