godot icon indicating copy to clipboard operation
godot copied to clipboard

Unable to Exporting Typed Arrays of Inner Classes

Open tjw123hh opened this issue 2 years ago • 1 comments

Godot version

4.0.stable

System information

Kubuntu 22.10, GLES 3, Intel HD Graphics 2000

Issue description

When trying to export typed arrays of a inner class, the type declaration in the resource file becomes Array[Object].

Steps to reproduce

# res://test.gd
class_name test
extends Resource

class example_class:
	extends Resource

@export var example_array: Array[example_class] = [example_class.new()]

Create a new "test.gd" resource in the editor and add an empty example_class to the example_array. Save the resource file to a file with a .tres extension. Open the file and you can see example_array = Array[Object]([null]).

Minimal reproduction project

N/A

tjw123hh avatar Mar 10 '23 11:03 tjw123hh

[example_class.new()] is a non-constant expression, so export won't work (at least without @tool). See #71091.

But it looks like inner classes are not supported, the "Cannot get class 'example_class'." error is displayed. As far as I remember, custom resources export requires a global name (class_name), which only scripts can have. In this case, we should add a compile-time error.

dalexeev avatar Mar 10 '23 12:03 dalexeev

Exported variables need scripts that can be identified by path. I didn't test, but const SCRIPT = preload(some script) can theoretically work too as a type. But inner classes and built-in scripts won't work.

KoBeWi avatar Mar 17 '23 01:03 KoBeWi