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

Files imported as custom resource types are not considered as resources #20496

Closed
paulloz opened this issue Jul 26, 2018 · 10 comments
Closed

Files imported as custom resource types are not considered as resources #20496

paulloz opened this issue Jul 26, 2018 · 10 comments

Comments

@paulloz
Copy link
Member

paulloz commented Jul 26, 2018

First of all sorry if this issue title is unclear. I can't find a better way to describe this in a quick way.

Godot version: 832e2bf

OS/device including version: Win10 x64

Issue description:
Here are possibly related issues I've found: #17395, #6763, #6067
I have this pretty simple plug-in defining a custom resource type and a resource importer.

tool
extends EditorPlugin

var import_plugin

func _enter_tree():
	add_custom_type("InkStory", "Resource", preload("ink_story.gd"), preload("icon.png"))
	import_plugin = preload("import_plugin.gd").new()
	add_import_plugin(import_plugin)

func _exit_tree():
	remove_import_plugin(import_plugin)
	import_plugin = null
	remove_custom_type("InkStory")

The import plugin is setting the resource_type like so.

tool
extends EditorImportPlugin

[...]

func get_resource_type():
	return "InkStory"

[...]

So far, everything's fine.
The import plug-in works like a charm:
image
And the custom resource type is shown in the list of exported properties (I used export (Resource) var Story):
image

However, even once imported, the icon aside the file here does not update (it's updating if the resource_type in the import plug-in is set to a built-in one):
image
More importantly, it's impossible to set this file/resource to the previously mentioned exported property (whether it is by drag'n'dropping it or using the Load button).


Bests ❤️

@wscalf
Copy link
Contributor

wscalf commented Apr 25, 2020

Hello from the future! Dunno if you're past this, but I'm running into something similar now. If you change the type returned from the EditorImportPlugin to "Resource", it lets you use either Load or drag'n'drop to associate a file to a resource slot, as you'd expect. I'm not sure what functionality you might lose by doing that, but at least so far it doesn't seem to hurt anything.

That might be all it takes, though I hit another snag after getting past that - the ResourceSaver doesn't seem to be serializing my resource correctly. I'm using C#, and it's possible it's a C#-specific issue and may not affect you. If it does, you can work around it by skipping the ResourceSaver and directly writing the tres file with the information you need to the file system (I used the inspector to generate one and then used it as a template.) I opened a separate ticket about that issue here: #38191

@NoodleSushi
Copy link

The first arguments passed on add_custom_type and remove_custom_type are pretty different ("InkStory" & "InkResource"), is that a typo?

@paulloz
Copy link
Member Author

paulloz commented Aug 4, 2020

is that a typo?

Yes, it is.

@AnidemDex
Copy link

However, even once imported, the icon aside the file here does not update (it's updating if the resource_type in the import plug-in is set to a built-in one)

I think that's #32706

Is this stills relevant @paulloz ? I can use imported files as resources in exported resource variables
godot_JHWotF3sN5

@paulloz
Copy link
Member Author

paulloz commented Apr 28, 2022

@AnidemDex Will check as soon as I can.

@AnidemDex
Copy link

@paulloz this is the reproduction project https://github.com/AnidemDex/Godot-CustomResource

@paulloz
Copy link
Member Author

paulloz commented Apr 29, 2022

So @AnidemDex, nothing changed AFAIK. Your example works because you are importing things as a Resource, not as an actual custom type. As soon as you'll change the return of get_resource_type from Resource to your custom type extending Resource you'll see the same behaviour as described in the original post.

@AnidemDex
Copy link

Maybe is related to this? godotengine/godot-proposals#18 (comment)

ClassDB can't found that type in native classes, so is not recognized as resource or that specific resource type

@willnationsdev
Copy link
Contributor

Yeah, I'm pretty sure this is a duplicate of #32706, as @AnidemDex mentioned. And it's definitely related to exported resources, but it's a bit more than that. The only way to fix this is to cache what scripted type and icon are associated with a file during the filesystem scanning process, that way the filesystem dock is able to render the icon without actually loading the entire resource. And the mentioned Issue already has a PR ready to implement it. Pretty sure this can be closed.

@Calinou
Copy link
Member

Calinou commented Jun 27, 2022

Duplicate of #32706.

@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2022
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

7 participants