Implementing Blueprint Interfaces

Blueprint Interfaces allow Blueprints to call functions in different types of targets, if they also implement the interface.

Choose your operating system:

Windows

macOS

Linux

Using Interfaces in Blueprints

The use of Blueprint Interfaces allows for a common method of interacting with multiple different types of objects that all share some specific functionality. This means you can have completely different types of objects, such as a car and a tree, that share one specific thing, like they can both be shot by weapon fire and take damage. By creating a Blueprint Interface that contains an OnTakeWeaponFire function, and having both the car and the tree implement that Blueprint Interface, you can treat the car and the tree as the same type and only call the OnTakeWeaponFire function when either of them is shot.

Adding Interfaces

Blueprint Interfaces as well as Interfaces defined in native code (C++) can be added to any type of Blueprint .

  1. From the Main Level Editor window, open the Level Blueprint inside your project.

    OpenLevelBP.png

  2. Click the Class Settings button from the Toolbar across the top.

    ClassSettings.png

  3. In the Details panel on the right, locate the Interfaces category.

  4. Click the Add Interface button to see a list of the available Interfaces and select the Inteface to use.

    InterfacesCategory.png

    InterfacesListPopulated.png

Interfaces can be removed by clicking the button_X_Remove.png button located next to each one on the Implemented Interfaces list. You can also migrate from Blueprint Interfaces to normal Blueprint functions. For more information, see Blueprint Interface Migration .

The Inherited Interfaces section within the Interfaces category automatically populates with any Interfaces that were inherited by this object (i.e. implemented in the Blueprint from which the current Blueprint was derived).

Implementing Interface Members

When an Interface is added to a Blueprint, that Blueprint must implement the Interface's functions in order to have them perform any action when called. This is done by placing Event nodes for the Interface functions in the EventGraph . The nodes connected to the Event define the functionality, or implementation, for the function.

  1. Right-click in the EventGraph of the Blueprint and choose Add Event > Event ...

    Implement Interface - Add Event Implement Interface - Event Node

    Select the type of Event you would like to add and the Event will be added to the graph.

  2. Create a network of nodes connected to the Event's executable pin to give it functionality.

    Implement Interface - Event Implementation

Calling Interface Functions

The functions of the Interface are executed through the use of Interface Message nodes, These look and act like regular Function Calls , except that they can fail silently if the target does not implement the Interface.

Implement Interface - Call Function

Calling Interface Functions on Other Blueprints

Interfaces are useful for allowing communication between different Blueprints. Functions from a single interface can be called on other Blueprints. This can be done when 2 criteria are met:

  • Both Blueprints implement the same interface with the required function.

  • The calling Blueprint knows the name of the in-game instance of the other Blueprint.

When creating an Interface Function node within the Event Graph, you will often see two versions of the function listed in the context menu.

MyFunctionInMenu.png

It is important to note that the version listed beneath Call Function is a local version, intended only to be called within this Blueprint.

The version listed under Interface Messages is designed to call the function via the interface on other Blueprints implementing the same interface.

There is some labeling beneath the node title in place to help differentiate:

Local_MyFunction.png

Interface_MyFunction.png

Local version.

Interface Message version.

Calling an Interface Message Function requires that you supply the instance of the appropriate Blueprint on which you are calling the function.

Note in this image we are sending another Blueprint as the Target input. This would call the function on the supplied Blueprint. If that Blueprint did not implement the interface, then nothing would happen.

InterfaceMessageFunctionCalled.png

To specify a Blueprint that exists within the level, it is best to make a Public variable of type 'Actor', and assign the appropriate Blueprint in the value for that variable using the Details tab of the Level Editor.

Calling Interface Functions on Level Blueprints

Interfaces can also allow for communication between sub-levels using the Get Streaming Level node. If the level is loaded and valid, the Interface Message will call the function with the level's Blueprint Script as the target.

InterfaceGetLevelStreaming.png

Overriding an Interface Function

One of the most important aspects of Interface functions is that, since they have no implementation of their own, their functionality can be independently defined for each Blueprint that implements the Interface.

Once an Interface has been implemented by a Blueprint, the functions of that interface will be visible in the My Blueprint panel.

iFunctionInExplorer.png

If you Double-click that function, it will open up within the Blueprint Editor. This shows the local implementation for this function. Whatever functionality is defined here will be unique to this Blueprint. In this way, you can define custom functionality for each Blueprint that implements the interface.

For example, in this image we see a basic Interface function as opened within a Blueprint. Right now, the function does nothing.

DefaultFunction.png

We could create a simple network to do a number comparison, and output the value, like so.

ComparisonFunction.png

Now, when the function is called locally, it will take in a float, compare it against the number 10, and then output the boolean result to the screen.

FunctionLogging.png

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss