[UE4]How to override BlueprintNativeEvent function which without virtual
Problem:
We want to override CalculateBaseMagnitude
that without virtual
:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="Calculation")
float CalculateBaseMagnitude(const FGameplayEffectSpec& Spec) const;
Solution:
Before compilation, UnrealHeaderTool generates the virtual function for a BlueprintNativeEvent in the base class. The example from above would look like:
virtual float CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const;
So in the derived C++ class, override (and implement) that function as usual in C++:
class PROJECT_API UGMMCCustom : public UGameplayModMagnitudeCalculation
{
float CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const override
{
float Ret = Super::CalculateBaseMagnitude_Implementation();
// Add your custom implementation in the cpp file.
return Ret;
}
}
Reference
https://stackoverflow.com/questions/55272245/how-to-override-a-blueprintnativeevent-function-in-c
幸运的人一生都被童年治愈,不幸的人一生都在治愈童年。----阿德勒