Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResourcePath to refer to a resource without preloading it #9216

Open
huwpascoe opened this issue Mar 2, 2024 · 6 comments · May be fixed by godotengine/godot#91815
Open

Add ResourcePath to refer to a resource without preloading it #9216

huwpascoe opened this issue Mar 2, 2024 · 6 comments · May be fixed by godotengine/godot#91815

Comments

@huwpascoe
Copy link

huwpascoe commented Mar 2, 2024

Describe the project you are working on

N/A

Describe the problem or limitation you are having in your project

There's no project-friendly way to reference resources without preloading them. There's a plain string with @export_file tag, but that's fragile and ineffective.

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

A new type called ResourcePath that the editor will track as if it were tracking an actual Resource.

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

# declare it manually and the editor could list as a dependency for the script
const res_1: ResourcePath = "res://thing.res"
const res_2: ResourcePath[Mesh] = "uid://..."

# or set the path from the inspector
@export var my_scene: ResourcePath[PackedScene]

func load_my_scene_on_demand():
  ResourceLoader.load_threaded_request(my_scene)
  # ...
  var s: PackedScene = ResourceLoader.get_threaded_request(my_scene)
  add_child(s.instantiate())

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?

It's a simple and obvious way to manage resource loading. It should be a core feature.

@KoBeWi
Copy link
Member

KoBeWi commented Mar 2, 2024

Check ResourcePreloader node.

@huwpascoe
Copy link
Author

Check ResourcePreloader node.

I've had a look, let's see how well ResourcePreloader fulfills the proposal...

  • Select resources from the UI without preloading them
  • Easy [generic] specifier to facilitate said UI
  • Allows editor to keep track of references and update them automatically
  • Only loads resources when they're called on

So...none of those.

Okay, perhaps I need to reword this proposal?

@KoBeWi
Copy link
Member

KoBeWi commented Mar 2, 2024

Easy [generic] specifier to facilitate said UI

What does that even mean?

Allows editor to keep track of references and update them automatically

But the ResourcePreloader meets this point.

Also currently the editor is not able to update resource paths if said resources are not listed in scene dependencies. And if they are dependencies, they are loaded with the scene. If you want auto-updating paths without loading, it would require some new system.

@huwpascoe
Copy link
Author

huwpascoe commented Mar 2, 2024

What does that even mean?

Well say you need a referenced for a PackedScene. You specify it as ResourcePath[PackedScene] so when you select it in the inspector, it doesn't show all derived from Resource, it only shows type of PackedScene

If you want auto-updating paths without loading, it would require some new system.

Yes, that's what this proposal is about.

@huwpascoe
Copy link
Author

Looking through the source at how much would need to be changed, I think an annotation would work better than a dedicated type like @export_ref var my_resource: Resource

@Calinou Calinou changed the title ResourcePath Add ResourcePath to refer to a resource without preloading it Mar 5, 2024
@simo498
Copy link

simo498 commented Apr 19, 2024

This issue was referenced on mine, i have a nearly identical problem and opened the same issue. Did you manage to prototype some code to add the feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants