Classes, structs, and other organizers

Hey y’all,

I have a bit of an organizational problem here. I want a character to have a set of abilities. Those abilities will share some data types (though the specific values will be unique, like the experience level) but each will also have several unique data types and functions.

For example, a simple hierarchical representation of this would be as follows:

  • Character
    • Abilities
      • Swimming
        • member variables and functions
      • Running
        • member variables and functions
      • Strength
        • member variables and functions
      • member variables and functions

Should Abilities be a struct containing classes for Swimming, etc as well as its own member functions/variables? Or perhaps a class that accesses the Swimming, etc classes and contains its own member variables and functions?

Or is there some completely different way you would recommend doing this?

This is a pretty good case for ActorComponents. Every ActorComponent you add to an actor is structure to give him a new ability.

That way, if you have any other actor that can swim, you just add the SwimmingComponent to him and he can swim!

I don’t kniw too much about it, but this seems like a good opportunity for inheritance. You make a class called Abilities and each ability is a class that inherits from Abilities.

So Running and Swimming will use all the code from Abilities, but each will contain the distinct code that makes them different from each other.

Privacy & Terms