List resources as options in dropdown in inspector for exported variable

Godot Version

4.3

Question

I am creating a skill system where each skill belongs to one of four categories: Power, Knowledge, Perception, Creativity. I have a SkillCategory class to contain some information that will be common to all skills under that category (right now it’s just the color that category’s skills should be displayed in).

class_name SkillCategory
extends Resource

@export var name: String = ""
@export var short_name: String = ""
@export_multiline var description: String = ""
@export_color_no_alpha var color: Color = Color.WHITE

I then have a resource created for each category.

In the BaseSkill class, one of the exported variables is the SkillCategory.

class_name BaseSkill
extends Resource

@export var name: String = ""
@export var short_name: String = ""
@export var category: SkillCategory = null
@export_file var icon: String = ""
@export_multiline var description: String = ""

I know I can then set the category in the inspector by clicking on the dropdown > Quick Load, and selecting the desired resource file.

But is there any way to pre-populate the dropdown with the four available SkillCategory resources, sort of similar to this screenshot where the dropdown is pre-populated with different Texture types. (I know it’s not quite the same thing since these are class types, not resources, but it’s the closest example I could find to what I’m going for).

There seems to be. Fair warning, I have not actually done this:

Look in the Resources section: “The drop-down menu will be limited to AnimationNode and all its derived classes.”

This suggests to me that is you make each one of those skill categories it’s own class then they should show up in the editor drop down.

As you noticed, your cat-ctv.tres etc. are instances, the items listed in Texture dropdown are classes. The dropdown lets you to create new instance of some class. The folder button lets you to select existing instance. So you can use only the folder button.

How about making an enum for the category:

enum Skill {Power, Knowledge, Perception, Creativity}

Then the BaseSkill would have:

@export var category: Skill = Skill.Power

Now you can select the category enum from a dropdown. You can map the enum to the actual SkillCategory resource easily behind the scenes. Just add the four skill category instances to a dictionary on to an array:

var categories: Dictionary[Skill, SkillCategory] = ...

(SkillCategory would be better name for the enum, but it would clash with the resource class name and I didn’t managed to invent a better name…)