(Godot version 4.6.2)
So, let’s say i have a class Action, that has a function execute(). My goal is to have a bunch of script that extends Action and overwrite the execute() function to handle specific tasks (like, move the character, or do an attack). Each of these new scripts can have specific parameters (like, distance for ActionMove, and damage for ActionAttack), and two instances of the same script can have different values for their parameters (like, one character moves 2 cells, the other one moves 3 cells).
I’d like those parameters to be editable from the editor, so i can assign an Action in a character node that exposes an Array[Action] and customize its parameters easily. I can do this by making the base class action extends Resource, but then, i can only create a base Action. Using the “Load” option of the Resource-assigning menu prevents from loading a .gd script, so i cannot immediately use all my scripts that extends Action.
To make this possible for all current and future Action-extended scripts, i have found multiple ways, and none of them is fully satisfying to me.
Option 1 - Register all Action-extended scripts as global classes
I can use class_name ActionMove (for the move action), and it makes it available in the editor, i don’t have to use the “Load” option. This seems to be how this person does it on another topic here.
My problem with it : if i have a lot of action, the list can grow quite big. It also feels dumb to me to register it editor-wide, when i really only need it in one place.
Option 2 - Use a setter to automatically switch to the specified script
I can expose a Script variable in the Action base class, with a setter that automatically applies it to itself, with something like this :
@export var custom_script : GDScript:
set(new_custom_script):
custom_script = new_custom_script;
if custom_script :
set_script(custom_script);
That way, in the editor, i create a new Action, set its custom_script property to an extended script like ActionMove, and it automatically applies it (if there is an @tool tag at the beginning of the script).
My problem with it : it feels very wonky, not very safe, requires one more step than just loading a .gd file, and the custom_script variable just hangs there in the parameters once it’s been used to load a custom script.
Option 3 - Use a .tres file for each Action-extended script
The editor menu allows me to load a .tres or .res file, so i could create one for each .gd script that extends Action, and use those instead.
My problem with it : it makes twice as much files, including one that has no real purpose. Also, i did not test it much but it seems that it doesn’t work if i don’t register the extended script with class_name, so if that’s needed anyway, Option 1 is much better.
Option 4 - Use Node instead of Resources
I could make the base class Action extends Node instead of Resource, and then export each extended script as a Packed Scene, that i would put in the Character’s node tree. I could build some structure to get the same “slot” system than an Array[Action].
My problem is it : it makes twice as much files, and it seems overkill to use scene for just a single script.
Now, i have a very limited knowledge of Godot, so i might be missing obvious options or obvious design principles that make all this a very dumb thing to do. I’d be happy to learn about what you know anyway, so if you have any advice on this, please share ! If i don’t find anything better, i’ll probably go with option 1, it seems the most logical one.



