Inner classes extend from RefCounted under the hood, so itâs not possible to export them to the inspector. You need to extend from Resource to be able to export and edit it in the inspector.
What youâre trying to achieve @joostonthegamer is just not possible by design. If you want to edit values in the editor, you have to create a new script that extends a Resource and then you can export that.
âWhy would we need inner classes for then?â you might ask. Itâs, well, for the purpose of the âinnerâ logic of the script. You can bundle a couple of variables together and pass these around instead of all variables separately. E.g. you might have a class Item that extends Resource, which holds basic information about an item like name, description, texture.
class_name Item
extends Resource
@export var name: String
@export var description: String
@export var texture: Texture2D
Then, in your Inventory.gd script you can have an inner class InventoryItem, which has just 2 variables:
class InventoryItem:
var item: Item
var count: int
You can then instantiate this class and pass around this info in your inventory, UI, etc. All should be handled internally without exporting these values to the inspector. If you ever need to export this information to the editor for whatever reason - it wonât work, you need to extend from Resource.
I searched my project to see if I ever used an inner class and this was the only instance:
class SaveFileMetadata:
var save_file_name: String
var game_version: String
var timestamp: String
@warning_ignore("shadowed_variable")
static func create_new(save_file_name: String, game_version: String, timestamp: String) -> SaveFileMetadata:
var new_save_file_metadata: SaveFileMetadata = SaveFileMetadata.new()
new_save_file_metadata.save_file_name = save_file_name
new_save_file_metadata.game_version = game_version
new_save_file_metadata.timestamp = timestamp
return new_save_file_metadata
I use it to create a list of information about save files, like save_file_name, game_version and timestamp, so I donât have to load a full save before showing this information in the Save/Load screen.
func get_save_files_metadata() -> Array[SaveFileMetadata]:
var array: Array[SaveFileMetadata]
var config: ConfigFile = ConfigFile.new()
config.load(saves_metadata_file_full_path)
for save_file_name: String in config.get_sections():
var game_version: String = config.get_value(save_file_name, "game_version")
var timestamp: String = config.get_value(save_file_name, "timestamp")
var metadata: SaveFileMetadata = SaveFileMetadata.create_new(save_file_name, game_version, timestamp)
array.append(metadata)
return array