godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.14k stars 21.19k forks source link

Can't have a null resource in import defaults of EditorImportPlugin #99267

Open jitspoe opened 4 hours ago

jitspoe commented 4 hours ago

Tested versions

v4.3.stable.official [77dcf97d8]

System information

Windows 10, Vulkan forward +, Nvidia 3070

Issue description

I'm trying to add an optional resource that can be specified in an importer as a preset to get around the shortcomings of the current preset system for imports mentioned here: https://github.com/godotengine/godot-proposals/issues/8350

Unfortunately, I cannot add an optional preset resource, as it seems impossible to have a resource type in the importer that can be set to null.

image

In this example, "preset_not_null" behaves as a resource and the editor allows users to specify a different resource or create a new one as normal. "preset_null", however just displays "" and clicking on the box does nothing, even though the hints are set up exactly the same.

If you right click and clear the preset_not_null, it will simply revert back to the default value.

I've also tried setting a "default_value" of Resource, which appears to work, until the .import file is read again, at which point there is an error parsing it and the import options are completely gone:

image

The errors are

Not setting the default_value isn't an option, as that errors out.

Steps to reproduce

Create an importer with a resource type in the importer options defaults, ex:

func _get_import_options(_path : String, preset_index : int):
    match preset_index:
        Presets.DEFAULT:
            return [
            {
                "name" : "preset_not_null",
                "default_value" : preload("res://addons/whatever_import/preset_example.tres"),
                "property_hint" : PROPERTY_HINT_RESOURCE_TYPE,
                "hint_string" : "WhateverImportPreset"
            },
            {
                "name" : "preset_null",
                "default_value" : null,
                "property_hint" : PROPERTY_HINT_RESOURCE_TYPE,
                "hint_string" : "WhateverImportPreset"
            },
            ]
        _:
            return []

Note that if the default value is set to null, the property cannot be used as a resource. If a resource is added by default, setting the resource to null will cause the resource to go back to the default value.

Minimal reproduction project (MRP)

import_resource_null.zip

jitspoe commented 2 hours ago

Another issue: If you store a resource in the importer settings and save that as the default, the project no longer loads: https://github.com/godotengine/godot/issues/83316