Hello, I’m writing a weapon system where each weapon can mount a module that defines weapon stats and other info (like muzzle particle system).
I want to create a lot of these modules and each module might have some specific functionalities triggered by the weapon (so I cannot think about these modules just as configurations).
I have a huge doubt about the architecture that I’m using here… this is what I wanted to achieve:
- A base UWeaponModule class from which the various modules inherit
- Each module can override base class values and behaviors
That being said, overriding the behaviors is quite simple since I can just override functions, but how can I override values? the only solution I found is to handle values as inline functions and have these functions returning the value… so that I can override these functions in the subclasses.
Here is an example of the base class… it defines a weapon that does a damage of 100, uses a specific particle system as the muzzle effect and cannot shoot bursts.
UCLASS()
class THEMIR_API UWeaponModule : public UObject
{
GENERATED_BODY()
public:
virtual bool burst() {
return false
}
virtual float getDamage() {
return 100.0f;
}
virtual FString getMuzzleEffectPath() {
return "/Game/Assets/Particles/Impacts/Particles/P_MuzzleSimple.P_MuzzleSimple";
}
virtual void fire(); // each module might have a different fire behavior.
};
Now I can easily subclass this class with an object that uses bursts, with a damage of 300 and so on…
I’m wondering if this is a good way to handle this logic… using a function to define what normally I’d define as a simple variable sounds a little bit strange to me.