Sometimes, you may need to create a UInterface
that specializes on a more general UInterface
.
This recipe shows you how to use inheritance with UInterfaces to specialize a Killable interface with an Undead interface that cannot be killed by normal means.
Create a
UINTERFACE
/IInterface
calledUKillable
.Add
UINTERFACE(meta=(CannotImplementInterfaceInBlueprint))
to theUInterface
declaration.Add the following functions to the header file:
UFUNCTION(BlueprintCallable, Category=Killable) virtual bool IsDead(); UFUNCTION(BlueprintCallable, Category = Killable) virtual void Die();
Provide default implementations for the interface inside the implementation file:
boolIKillable::IsDead() { return false; } voidIKillable::Die() { GEngine->AddOnScreenDebugMessage(-1,1, FColor::Red,"Arrrgh"); AActor* Me = Cast<AActor>(this); if (Me) { Me->Destroy(); } }
Create a new
UINTERFACE
/IInterface
calledUndead
. Modify them to inherit...