Skip to content

Add PROPERTY_HINT_RESOURCE_FILE to soft-reference Resources #12768

Open
@Ryan-000

Description

@Ryan-000

Describe the project you are working on

I’m developing a large game where exported scenes, textures, and other resources must be referenced by path/UID to keep load times and memory usage low.


Related:
#8484
#9216
#10869

Describe the problem or limitation you are having in your project

Godot today offers two separate hints:

  • PROPERTY_HINT_FILE - lets you pick files by extension (e.g. *.tres,*.res,*.tscn), but has no type safety and requires manually maintained glob lists.

  • PROPERTY_HINT_RESOURCE_TYPE - filters by resource type, but stores the object reference (causing load).

I need the type safety and Editor UX of PROPERTY_HINT_RESOURCE_TYPE, while having the underlying behaviour of PROPERTY_HINT_FILE (so large resources aren’t loaded until needed)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Introduce a new hint, PROPERTY_HINT_RESOURCE_FILE, which functions just like PROPERTY_HINT_RESOURCE_TYPE but stores a path or UID as a String instead of the object reference.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  1. Add the hint to PropertyHint

  2. Modify EditorPropertyPath to optionally have a dropdown on right side (just like EditorResourcePicker) for "Quick Load" and "Load".

  3. Modify EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property in the String case to setup the EditorPropertyPath accordingly when the hint is PROPERTY_HINT_RESOURCE_FILE.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

A lot of core code can actually benefit from this, here are some examples:

For example this
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), "");

Could turn to
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_RESOURCE_FILE, "PackedScene"), "");

https://github.com/godotengine/godot/blob/c6d130abd9188f313e6701d01a0ddd6ea32166a0/core/register_core_types.cpp#L326

https://github.com/godotengine/godot/blob/c6d130abd9188f313e6701d01a0ddd6ea32166a0/core/config/project_settings.cpp#L1612

https://github.com/godotengine/godot/blob/c6d130abd9188f313e6701d01a0ddd6ea32166a0/editor/import/3d/resource_importer_scene.cpp#L2173

https://github.com/godotengine/godot/blob/c6d130abd9188f313e6701d01a0ddd6ea32166a0/main/main.cpp#L2757

https://github.com/godotengine/godot/blob/c6d130abd9188f313e6701d01a0ddd6ea32166a0/scene/theme/theme_db.cpp#L52

https://github.com/godotengine/godot/blob/c6d130abd9188f313e6701d01a0ddd6ea32166a0/scene/theme/theme_db.cpp#L53

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions