Resource based ability system

Godot Version

Replace this line with your Godot version

Question

I’ve been trying to make a system for abilities in my 3d godot game. I originally tried the method I had used previously for guns in a fps game I made. Defined a bunch of stat’s and had a managing node handle instantiating from the resource ect. But I found that I wanted a more broad range of things for abilities to do. You know, defining ammo on a ability that teleports you seems messy, and I thought that might be fine as long as I used modular terminology for the resources things such as func use() and stuff like that but I was having a hard time with resources only being able to have data pulled out and not put any data into them. After that I tried having resources house a script that I append to the player so that they can run it, this fixed the 2 way data stream issue but the player became a God object with so much data housed in them. I want a system where I can run custom logic for different abilities stored in resources that has no issue communicating between the resource the player and the world. If anyone has had a similar problem I’d appreciate some insight

func _ready() -> void:
    print("hello world")

It’d be easier to help with some specifics. But I handle what sounds like the same problem with state machines.

I use a pull-based state machine from my State Machine Plugin. So I can add and remove abilities in real time and they don’t affect anything else. For example, my Jump state looks like this:

Basically, I leverage the Node-based system that Godot supplies.

class_name ExampleResource
extends Resource

var attrib

func modify_attrib() -> void:
   # Functionality for the attrib

Resources in Godot are one of my favorite ways to have modular functionality.

You could give each ability a dictionary of attributes the same way you gave them all a use() function, and then whatever objects are trying to modify the attribute of an ability could check the dictionary keys to see if the ability has the attribute before modifying it. An additional benefit of doing that is that you could then update the attributes directly in the editor by exporting the dictionary property.