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...

  1. Create a UINTERFACE/IInterface called UKillable.
  2. Add UINTERFACE(meta=(CannotImplementInterfaceInBlueprint)) to the UInterface declaration.
  3. Add the following functions to the header file:
    UFUNCTION(BlueprintCallable, Category=Killable)
    virtual bool IsDead();
    UFUNCTION(BlueprintCallable, Category = Killable)
    virtual void Die();
  4. 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.