Hello community,

I have written a tool script for saving FBX-Files as separate scenes while importing them with the import script set. In Godot 3.5 (and lower) it worked like a charme. Simply select a FBX file in the editor file system dock, set the script in the import option and it works.
In Godot 4 I did the same, but it seems that the script won't be executed. All print() command don't gave me an output and I don't get the seperatly saved scene.

@tool # Needed so it runs in the editor.
extends EditorScenePostImport

func _save_scene(o: Object, path: String) -> void:
	var packed_scene = PackedScene.new()
	packed_scene.pack(o)
	var file_name = FileUtilities.ensure_path_delimitter(path)+o.name+".tscn"
	var file_exists = FileUtilities.file_exists(file_name)
	print("_save_scene() -> file_name: "+file_name)
	if not file_exists: # or override_existing_prefab:
		# if file exists change output to "overriden"
#		if file_exists:
#			var ok_text = "Prefab overridden: " + file_name
#		var error = ResourceSaver.save(file_name,packed_scene)
		ResourceSaver.save(file_name,packed_scene)
#		if error == OK:
#			print("Scene saved as: " + file_name)
#		else:
#			print("Scene not saved (Code: " + error + ")")


func _set_owner(n: Node, p: Node) -> void:
	if not n == p:
		n.set_owner(p)
	for child in n.get_children():
		_set_owner(child,p)

func post_import(scene):
	print_debug("post_import")
	var base_dir = self.get_script().get_path().get_base_dir()
	print(base_dir)
	var new_scene = scene.duplicate(15)
	_set_owner(new_scene,new_scene)
#	_save_scene(new_scene,base_dir+"/Prefabs")
	_save_scene(new_scene,"res://Assets/PFK/Prefabs")
	return scene # remember to return the imported scene

Maybe someon can help. As I said in Godot 3.5 it works like a charm.

Cheers Z3R0PTR

Edit:

Even this simple script won't give me an output:

  • I solved the issue. The post import function is renamed in Godot 4.

    Godot 3.5:

    func post_import(scene):

    Godot 4:

    func _post_import(scene):

    So this problem is solved. 🙂

I solved the issue. The post import function is renamed in Godot 4.

Godot 3.5:

func post_import(scene):

Godot 4:

func _post_import(scene):

So this problem is solved. 🙂