Generic, extendable and easy to use damage system for any game.
Damage System is part of Game Dev Tools Plugin.
Features
- Created using UE4 SubSystem,
- Damage Data can be extended and modified during damage,
- Helper functions: ModifyDamage, MultiplyDamage, GetBackstabDot, GetDotToTarget, GetCreatedTime,
- Using interface to deal damage,
- Works with Health Component
Documentation
Example Map
Example map can be found here:
\Plugins\GDMegaPack\Content\Health\Maps\Showcase_GDHealthAndDamage.umap
Applying Damage
To Apply damage use ApplyDamage function from DamageSubsystem. You need to create DamagaData and pass it. Apply damage will call Damage Receiver Interface.
To apply damage it in C++:
1 2 3 4 5 6 7 8 9 10 11 |
// get game instance UGameInstance* GameInstance = GetGameInstance(GetWorld()->GetGameInstance()); // get damage subsystem from game instance UGDDamageSystem* DamageSystem = GameInstance->GetSubsystem<UGDDamageSystem>(); // create new damage data UGDDamageData* DamageData = UGDMegaPackFunctionLibrary::CreateGDDamageData(this, UGDDamageData::StaticClass()); // apply damage to target using new damage data DamageSystem->ApplyDamage(DamageData, Victim); |
Receiving Damage
To receive damage Actor need to implement GDDamageReceiver Interface.
This can be done in Blueprints in Class Settings:
Then you will have two functions. CanTakeDamage and TakeDamage:
Normally Apply Damage do nothing you need to plug in your health system. You can use Health Component from Plugin like here:
To receive damage in C++ you need to add interface to your Actor and override interface functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
UCLASS() class GDMEGAPACKPROJECT_API AActorWithDamageReceiverInterface : public AActor, public IGDDamageReceiverInterface { GENERATED_BODY() public: // Sets default values for this actor's properties AActorWithDamageReceiverInterface(); bool TakeGDDamage_Implementation(const UGDDamageData* DamageData) override { return true; } bool CanTakeGDDamage_Implementation(const UGDDamageData* DamageData) override { return true; } } |
FAQ
Why not use UE4 Apply Damage?
Default UE4 Damage implementation have two problems:
- You can’t extend damage structure in Blueprints. For example if you want to use your data you need to create your own functions to deal damage with your custom structure ignoring UE4 Damage implementation,
- Damage informations can’t be changed during runtime as it’s const,
Damage System can be easyly extendable: create your own Damage Data, override ApplyDamage functions and use interface to receive damage.