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

  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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 18
  • Comments: 19 (3 by maintainers)

Most upvoted comments

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.

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

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