godot
godot copied to clipboard
Error when setting exported custom resource field to be a new resource
Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.
Godot version
4.0.beta2
System information
Ubuntu 20.04
Issue description
When attempting to set the value of an exported custom resource field of type TestResource
(extending Resource
) by using the "New TestResource" option through the editor, the following error is emitted:
Failed to set a resource of the type 'Resource' because this EditorResourcePicker only accepts 'TestResource' and its derivatives.
Steps to reproduce
- Create a custom resource with class name
TestResource
extendingResource
with a single exported field.
extends Resource
class_name TestResource
@export var field := ''
- Create a custom node type with class name
TestNode
extendingNode
with a single exported field of typeTestResource
.
extends Node
class_name TestNode
@export var node: TestResource
- Create a node of type
TestNode
. - Click on the created node. The
Node
field should be<empty>
. - Try to set the
Node
field using the "New TestResource" option. The observed error will be emitted.
Minimal reproduction project
Can confirm same bug for Windows 10, Godot 4.0.beta2
Same in 4.0 beta 4, on MacOS 12.3.1, Apple M1
I'm seeing the same error, but also with an additional bug where any nested resources are deleted when the resource script is modified. I'm on Windows 11, 4.0 beta8.
Details and repro steps:
The original repro project does not repro for me. But, if I add a new resource test_resource2.gd
:
extends Resource
class_name TestResource2
@export var field2: int = 100
and modify test_resource.gd
to export a variable of that new resource type:
extends Resource
class_name TestResource
@export var field := ''
@export var res : TestResource2 // <--- added field
then I see the Failed to set a resource of the type 'Resource' because this EditorResourcePicker only accepts 'TestResource2' and its derivatives.
error. Worse though, if you create the nested resource through the editor, save, and then edit the resource script (test_resource.gd
) then the nested resource is deleted (the resource field will be <empty>
).
Related to https://github.com/godotengine/godot/issues/69356 (possible duplicate?).
I'm also having this issue on 4.0 beta 10.
I have an exported array of dialogue resources. I can make a few dialogue resources via the editor, but if I change the size of the array and add a new resource, the items are reset.
Also encountering this with beta 10.
This is still a thing in v4.0.beta16.mono.official [518b9e580]
I just ran into this issue which makes me sad because the custom resources were making my life easier
Please make sure you guys fix this with tool scripts too. I don't know if it's a issue but I kinda need to draw where my engine thrusters are
Can confirm it still happens with v4.0.rc1.official [8843d9ad3].
Also getting this error in v4.0.rc.1 official
Also getting this error in v4.0.rc.2 official
I'm still getting this, it seems like a viable way to do things. I'm on latest 4.1.2. Am I doing something wrong?
Restarting the editor fixed the problem.
I'm not getting the error, but the exported variable is always null for me, even though it has a Resource assigned to it in the scene:
(I'm using version 4.2.beta3
-> Inspector with the Custom Resource assigned to the exported variable:
-> Remote view of the same Node with the exported variable null:
Why is this closed? Just happened to me in Godot 4.2 on Mac M1
This issue still exists as of Godot 4.2.1 on Ubuntu 22.04.
Why is this closed? Just happened to me in Godot 4.2 on Mac M1
This issue still exists as of Godot 4.2.1 on Ubuntu 22.04.
This is what worked for me. Resource _init
must have default values for all parameters.
Then instantiate resource on export:
extends CanvasItem
@export var my_resource: MyResource # <- this won't work
@export var my_resource: MyResource = MyResource.new() # <- this works
The issue still exists, and the workaround above did not work for me, I got Invalid call. Nonexistent function 'new' in base 'GDScript'.
This should not be closed, even if the workaround worked.
My guess is that there is an issue in the ordering of the Custom Resources definition. The subresource may not yet be defined when the top resource is defined.
And also I did encounter this bug... If I use @export var test: MyExtendedResource
and set it in the editor when playing the game it is null!
Godot v4.2.1.stable - Windows 10.0.18363 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1050 (NVIDIA; 31.0.15.5176) - Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 Threads)