godot
godot copied to clipboard
"The selected resource does not match any type expected for this property" error with custom resource types
Godot version: 3.2.3
OS/device including version:
- macOS 10.15.7
- Windows 10
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:
- Create two custom types that extend the "Resource" type. In the second one ("parent") add a parameter that references the other ("child") (can be done using _get_property_list)
- Create a child resource by right clicking in the file system browser and selecting "Create Resource" and select the child resource's type
- Save that resource
- Create parent resource
- In the inspector for the referencing variable, select the previously created child resource
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.
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
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.
Thanks a lot!
I am still having this issue using the latest 4.0 beta.
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
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 :(
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 "
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)
@sambskn Have you tried marking that custom resource as a named script? I think using C#'s Global Class worked for me.
I'm also faced with this issue, the typing is clearly correct but refuses to take it. Very frustrating!
@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
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
This should've been fixed already. Does anyone have up-to-date minimal reproduction project?
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:
- double click any of the card pile resource files and go to Inspector
- click on Card and try to Quick Load anything
Result:
- only 1 of 4 card resources can be loaded (the one that has card.gd in RefCounted in inspector)
- I've had quite inconsistent behavior here - sometimes I can add only that 1, sometimes I can't add any. Restarting Godot/reimporting the project sometimes helps, sometimes breaks what was working. At the moment I can't load any card resource with Quick Load and I restarted 5+ times, it worked fine for 1 card when I initially created the project.
Case2 - Load:
- double click any of the card pile resource files and go to Inspector
- click on Card and try to Load each of the 4 card resources
Result:
- card_1 and nested_card_1 can be loaded (first one because its script has defined class_name, second one because it extends Card directly)
- card_2 and nested_card_2 can't be loaded
Case3 - Drag & drop:
- double click any of the card pile resource files and go to Inspector
- try to drag & drop each of the 4 card resources into Card field
Result:
- all 4 cards can be loaded
Hope this makes sense.