godot icon indicating copy to clipboard operation
godot copied to clipboard

Error when setting exported custom resource field to be a new resource

Open es1024 opened this issue 1 year ago • 8 comments


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

  1. Create a custom resource with class name TestResource extending Resource with a single exported field.
extends Resource
class_name TestResource
@export var field := ''
  1. Create a custom node type with class name TestNode extending Node with a single exported field of type TestResource.
extends Node
class_name TestNode
@export var node: TestResource
  1. Create a node of type TestNode.
  2. Click on the created node. The Node field should be <empty>.
  3. Try to set the Node field using the "New TestResource" option. The observed error will be emitted.

Minimal reproduction project

resource-test.zip

es1024 avatar Oct 04 '22 04:10 es1024

Can confirm same bug for Windows 10, Godot 4.0.beta2

codingvessel avatar Oct 16 '22 22:10 codingvessel

Same in 4.0 beta 4, on MacOS 12.3.1, Apple M1

michaelgundlach avatar Nov 02 '22 16:11 michaelgundlach

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>).

godot-nested-resource-bug

sfreed141 avatar Dec 16 '22 23:12 sfreed141

Related to https://github.com/godotengine/godot/issues/69356 (possible duplicate?).

Calinou avatar Dec 17 '22 01:12 Calinou

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.

aMytho avatar Jan 06 '23 22:01 aMytho

Also encountering this with beta 10.

muno777 avatar Jan 10 '23 15:01 muno777

This is still a thing in v4.0.beta16.mono.official [518b9e580]

derkork avatar Jan 28 '23 14:01 derkork

I just ran into this issue which makes me sad because the custom resources were making my life easier image

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

Shadowblitz16 avatar Jan 28 '23 22:01 Shadowblitz16

Can confirm it still happens with v4.0.rc1.official [8843d9ad3].

animentork avatar Feb 12 '23 22:02 animentork

Also getting this error in v4.0.rc.1 official

rodeyfeld avatar Feb 13 '23 01:02 rodeyfeld

Also getting this error in v4.0.rc.2 official

gibionmillak avatar Feb 16 '23 13:02 gibionmillak

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?

image

Andrew1431 avatar Oct 09 '23 04:10 Andrew1431

Restarting the editor fixed the problem.

Andrew1431 avatar Oct 09 '23 06:10 Andrew1431

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: image

-> Remote view of the same Node with the exported variable null: image

lucassene avatar Nov 01 '23 07:11 lucassene

Why is this closed? Just happened to me in Godot 4.2 on Mac M1

AndreiSchapov avatar Dec 09 '23 15:12 AndreiSchapov

This issue still exists as of Godot 4.2.1 on Ubuntu 22.04.

peck94 avatar Dec 25 '23 01:12 peck94

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

mabysh avatar Dec 25 '23 08:12 mabysh

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.

BimDav avatar Mar 06 '24 09:03 BimDav

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)

Ashenguard avatar Apr 01 '24 20:04 Ashenguard