Bitwaker
(Bitwaker)
January 31, 2019, 5:44pm
5
@OptimisticMonkey
anonymous_user_5c3425f1isticMonkey:
Since the internal application of damage will vary by object class, an alternative approach might be to simply use a defined interface to apply the damage.
Each class’s implementation of ReceiveDamage can be class specific, but there is no coupling between sender and receiver.
When sending damage, it is often useful to pass additional info such as damage type, amount, hit information, bone name, etc…
And while the built-in damage system covers many of these bases, I often find it better to roll your own.
Yes I do like the interface logic. I’ll review my current implementation. At the moment I’ve implemented inside the BeginPlay method an handler for the OnTAkeAnyDamage called on the component owner:
void UDamageComponent::BeginPlay()
{
Super::BeginPlay();
AActor *Owner = GetOwner();
if (Owner != nullptr) {
Owner->OnTakeAnyDamage.AddDynamic(this, &UDamageComponent::HandleTakeAnyDamage);
}
}