godotengine / godot

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

Can't assign subclass of custom resource in property that expects a given resource type in the inspector #92330

Open deonix37 opened 3 months ago

deonix37 commented 3 months ago

Tested versions

4.2.2.stable

System information

Godot v4.2.2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Ti Laptop GPU (NVIDIA; 31.0.15.5123) - 11th Gen Intel(R) Core(TM) i5-11300H @ 3.10GHz (8 Threads)

Issue description

I have (card.gd):

class_name Card
extends Resource

And (random_card.gd)

class_name RandomCard
extends Card

If i do this, then I can drag & drop the random_card.gd script that extends Card into the export field, but it doesn't really work, it gives the error: "Failed to set a resource of the type 'GDScript' because this EditorResourcePicker only accepts 'Card' and its derivatives.". Even though it is a subclass:

@export var initial_card: Card

Steps to reproduce

description

Minimal reproduction project (MRP)

N/A

deonix37 commented 3 months ago

See also

santouits commented 3 months ago

Unless I didn't misunderstand what you are doing, this is normal. What the variable expects to drag there is a .tres file that contains the data of a card and you are dragging the script that defines the resource. You can create such a file with the create new resource button in your inspector and selecting the Card or RandomCard resource.

deonix37 commented 3 months ago

Unless I didn't misunderstand what you are doing, this is normal. What the variable expects to drag there is a .tres file that contains the data of a card and you are dragging the script that defines the resource. You can create such a file with the create new resource button in your inspector and selecting the Card or RandomCard resource.

You are right, I just figured out what I wanted to do is @export var card: GDScript, and it works fine. But looks like there's just another bug related to exporting custom resources

AThousandShips commented 3 months ago

This is as expected, a script isn't the class it defines, you need to create a resource file instead, as explained above, unsure how this can be documented further though