Why is my custom file import plugin not working?

Godot Version

4.6.2

Question

Hello, I am trying to make a importer for a custom filetype, (noted as .csl).

It should simply take each line of the file, puts each in a arrat in a resource called CSLScript.

But when I drag the file into the FileSystem, nothing happens.

How do I fix this?

Also, yes it is proprely enables as it appears in the import defaults part of the project settings.

@tool
class_name CSLImportPlugin
extends EditorImportPlugin

const VERSION: int = 1

func _get_importer_name():
	return "csl.importer"

func _get_format_version() -> int:
	return VERSION

func _get_visible_name():
	return "CSL file"

func _get_recognized_extensions() -> PackedStringArray:
	return PackedStringArray(["CSL"])

func _get_save_extension():
	return "csl"

func _get_resource_type():
	return "Resource"

func _get_preset_count():
	return 0

func _get_preset_name(preset_index):
	return "Unknown"

func _get_import_options(path, preset_index):
	return []

func _import(source_file, save_path, options, platform_variants, gen_files):
	var file = FileAccess.open(source_file, FileAccess.READ)
	if file == null:
		return FAILED
	var csl = CSLScript.new()
	
	while file.get_position() < file.get_length():
		csl.lines.append(file.get_line())
	var filename = save_path + "." + _get_save_extension()
	return ResourceSaver.save(csl, filename)

Try adding import order and priority, and increase your present count to 1?

func _get_preset_count() -> int:
	return 1

func _get_priority() -> float:
	return 1.0

func _get_import_order() -> int:
	return 0

Maybe try a different save extension than the recognized extension too, .res would be best for Resources.

I tried this, but no result :frowning:

@tool
class_name CSLImportPlugin extends EditorImportPlugin

const VERSION: int = 1


func _get_importer_name():
	return "csl_importer"


func _get_format_version() -> int:
	return VERSION


func _get_visible_name():
	return "CSL file"


func _get_import_order() -> int:
	return 0


func _get_priority() -> float:
	return 1.0


func _get_resource_type():
	return "Resource"


func _get_recognized_extensions() -> PackedStringArray:
	return PackedStringArray(["CSL"])


func _get_save_extension():
	return "res"


func _get_preset_count():
	return 1


func _get_preset_name(preset_index):
	return "Unknown"


func _get_import_options(path, preset_index):
	return []

func _get_option_visibility(path: String, option_name: StringName, options: Dictionary) -> bool:
	return false

func _import(source_file, save_path, options, platform_variants, gen_files):
	var file = FileAccess.open(source_file, FileAccess.READ)
	if file == null:
		return FAILED
	var csl = CSLScript.new()
	
	while file.get_position() < file.get_length():
		csl.lines.append(file.get_line())
	var filename = save_path + "." + _get_save_extension()
	return ResourceSaver.save(csl, filename)

Try making this true, or removing the function (the default is true)

I made the “CSL” lowercase in _get_reconized_extension(), to “csl” even if the files real extension is uppercaes, it seems to work. why? no clue. but no complaining.

1 Like

This is why. Case matters.