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

Allow resources without class_name to be created in the EditorResourcePicker #8102

Open
dugramen opened this issue Oct 13, 2023 · 9 comments

Comments

@dugramen
Copy link

Describe the project you are working on

Editor plugins

Describe the problem or limitation you are having in your project

When exporting a resource, you get an EditorResourcePicker in the inspector. It shows a list of extended resources which can be created, but only ones that have an explicit class_name. Subsequently it seems like you can't have built-in anonymouse resources at all, since to create that resource you'd have to make a new file and drag that in

I'd like anonymouse resource classes so that it doesn't pollute the list of class names

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

Allow anonymous resource classes to be created in the resource picker. This would enable anonymouse resources to be built in and not pollute the class list namespace or the filesystem

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

I have 2 suggestions

  1. Include anonymous resource classes in the ResourcePicker list. Their 'name' would be the script's resource_path. Since that could be really long and ugly, make a submenu for anonymous resources under "more ->"

  2. Allow dragging and dropping a script into the resoruce picker, and if it inherits the proper resource, create a built in instance (a new resource with that script attatched). Of course, since scripts are also resources, ignore this feature when the resource picker expects a script

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

Possibly? But it would be very hacky and not easy

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

EditorResourcePicker is core

@AThousandShips
Copy link
Member

AThousandShips commented Oct 13, 2023

What's the problem with naming the class? Pollution aside this would make things more complicated code side I'd say, and it works against how the system is designed

@dugramen
Copy link
Author

Naming the class isn't a huge problem or anything, but it does make things less sharable. I'll give the context of my project as an example

The plugin I'm working on is a custom stylebox that accepts a list of resources to change its properties via code. This is specifically to tackle the pain point of getting things like the 'accent_color' and 'base_color' from editor settings. Ideally someone would only have to share the theme.tres file to get the same theme, so it would be beneficial to have everything built in and anonymous, in case there is some naming clash

Again not a huge deal, but I think it should be possible at least

@AThousandShips
Copy link
Member

Built in scripts wouldn't work with this, they're limited and adding support for them would be a lot more work

@KoBeWi
Copy link
Member

KoBeWi commented Oct 13, 2023

You can create empty Resource and attach script.

@dugramen
Copy link
Author

Ok so my main issue was that I thought built in resources was not possible without class_name, but I just realized that clicking "make unique" literally just makes a resource, even scripts, built in. So I can work with that

@Tattomoosa
Copy link

I think adding namespaces would be the ideal solution here as far as I'm concerned (namespace proposal) since class_name pollution/collision is the primary reason to avoid it, especially when developing addons.

I also would be for adding a "Load Script" option into the inspector's resource picker and the create resource dialog to facilitate creating new anonymous resources, but I think with namespaces there wouldn't be much incentive to have anonymous resources in the first place.

Something related to this though that I think is a bug is that resources with anonymous scripts (existing .tres files) cannot be loaded via Quick Load or Load, and must be drag and dropped from the FileSystem. Fixing that would go a long way towards making anonymous resources more usable.

@rvenson
Copy link

rvenson commented May 21, 2024

You can create empty Resource and attach script.

It seems not possible to attach a resource to a node using the editor (drag-n-drop or EditorResourcePicker).

extends Resource
@export var name : String
@export var production_time : int
extends Node
const Recipe = preload("res://recipe.gd")
@export var selected_recipe : Recipe

Via scripting, it works. There are any workarounds to this issue (if I do not want to use the class_name)?

@KoBeWi
Copy link
Member

KoBeWi commented May 21, 2024

Ii you export Recipe, the editor will accept only resources that have a script named Recipe attached, or its derivatives. For nameless scripts you'd need to export plain Resource.

@rvenson
Copy link

rvenson commented May 21, 2024

Yeah, I see. It misses the point of exporting the variable for me since it could lead to the wrong resource type being attached to the node or more code to type check. Class names still are not an option for me without namespaces. Thanks for the clarification.

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

No branches or pull requests

5 participants