godotengine / godot

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

"The selected resource does not match any type expected for this property" error with custom resource types #45015

Open dploeger opened 3 years ago

dploeger commented 3 years ago

Godot version: 3.2.3

OS/device including version:

Issue description: When referencing custom resource types in other custom resource types and loading a resource file that was previously created based on that resource type the following error is displayed:

The selected resource (Resource) does not match any type expected for this property (ChildResource).

The resource can be used, though.

Steps to reproduce:

Minimal reproduction project: CustomResourceTest.zip

In this project: Open the file "parent_test.tres" in the inspector and select the file "child_test.tres" for the parameter "child" to see the error.

KoBeWi commented 3 years ago

This might be a general problem with Resources not strictly a bug, see https://github.com/godotengine/godot-proposals/issues/18 There's a PR that likely solves this issue #41264

willnationsdev commented 3 years ago

I'll try to test your sample project with my PR's build to see if the issue is fixed by it. If not, I'll work on adding the fix to the PR's changes.

dploeger commented 3 years ago

Thanks a lot!

isaaccp commented 1 year ago

I am still having this issue using the latest 4.0 beta.

isaaccp commented 1 year ago

It actually worked after restarting Godot. I think maybe it wasn't going inside this if: https://github.com/godotengine/godot/blob/eaf306e0b15e4283883f06bf903b05711a4dbfe8/editor/editor_resource_picker.cpp#L139

Martanti commented 8 months ago

I faced this issue when using Godot 4.2.1 mono build. Tried restarting the engine as per @isaaccp recommendation, but it didn't help :(

sambskn commented 7 months ago

Still experiencing this issue fairly commonly in 4.2.1. Sometimes a restart of the editor helps, but not always. When I try to change the values of a custom resource that has custom resources as export vars, it complains that I'm trying to put a "Resource" where a "" belongs. It definitely feels like a bug, I've ran into the case where removing a valid export var with a custom resource type, then trying to add the same file/resource again will throw the error, even though inspecting the resource in the editor shows that it's extending the custom class/resource.

I can get around this by changing my custom resource's @export var from a type of Array[<custom resource class>] to Array[Resource], updating the array value for the custom resource I want to edit to have the new custom resource in the array, then changing the type of the @export var back. A little dirty, and I don't like scrolling past every new resource option just to get to Load lol.

Inspecting the resources throwing the error in VS Code, I noticed they didn't have the script_class="<custom resource name>" of the resource class they extend, but adding that in did not solve the issue (also tried clearing my .godot directory)

Martanti commented 6 months ago

@sambskn Have you tried marking that custom resource as a named script? I think using C#'s Global Class worked for me.

Access547 commented 6 months ago

I'm also faced with this issue, the typing is clearly correct but refuses to take it. Very frustrating!

sambskn commented 6 months ago

@sambskn Have you tried marking that custom resource as a named script? I think using C#'s Global Class worked for me.

Not sure I follow what you're saying. Is this an edit I can make on the file itself? It's gdscript not C# FWIW

stefan-zdravkovic commented 4 months ago

I faced this issue only when I try to load resources from Inspector menu (quick load shows no results, load produces the error message described above). If I drag & drop the same resource from the FileSystem, it works as expected.

v4.2.2, Windows 10

KoBeWi commented 4 months ago

This should've been fixed already. Does anyone have up-to-date minimal reproduction project?

stefan-zdravkovic commented 4 months ago

Took me a while to get the right data, but here it is: resource_test.zip

To make it easier to understand I used a realistic example. Practically, we have Card and CardPile classes (card pile contains 1 card, but same issue happens with arrays).

Then we have 4 classes that extend Card and a resource for each of those. 3 resources have a corresponding Card child class as its RefCounted script (card_1, card_2 and nested_card_2), 1 was left with the base Card.gd on purpose (nested_card_1).

We also have 2 resources for CardPile (no child classes were made for those, but I don't think it's relevant).

Case1 - Quick Load:

Result:

Case2 - Load:

Result:

Case3 - Drag & drop:

Result:

Hope this makes sense.