Yes, it's possible to create a custom file extension for your resources and filter the FileDialog to only show files with that extension. Here's how you can do it in Godot:
Custom File Extension: You can indeed use a custom file extension like .exp
for your resources. Just make sure to use this extension when saving your resource files.
Filtering FileDialog: When you open the FileDialog in Godot, you can set the filters
property to specify which file types should be shown. You can create a custom filter that only allows files with your custom extension.
Here's an example of how you can set up the FileDialog in Godot to only show files with the .exp
extension:
extends Control
var file_dialog
func ready():
file_dialog = FileDialog.new()
file_dialog.set_access(FileDialog.ACCESS_FILESYSTEM)
file_dialog.set_mode(FileDialog.MODE_OPEN_FILE)
file_dialog.set_filters([["*.exp", "Exp Files"]])
file_dialog.connect("file_selected", self, "on_file_selected")
add_child(file_dialog)
func _on_button_pressed():
file_dialog.popup_centered()
func _on_file_selected(path):
print("Selected file:", path)
In this example, *.exp
is the filter pattern that specifies files with the .exp
extension, and "Exp Files"
is the label shown in the FileDialog's filter dropdown menu. Adjust these values according to your specific file extension and label.
With this setup, the FileDialog will only allow the user to select files with the .exp
extension, ensuring that only resources of that type are chosen.