O'Reilly logo

Unreal Engine 4 Scripting with C++ Cookbook by Stephen Whittle, William Sherif

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required