Inheriting UInterface from one another
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.
How to do it...
- 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; ...
Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.