How, why and when you should use Blueprint Interfaces in Unreal Engine 5.
This tutorial will cover blueprint interfaces, what they are and how, why and when you would like to use them. Made by Beardgames, a YouTube channel that is dedicated towards creating informative tutorials for Unreal Engine and Blender.
Blueprint interfaces allow you to communicate with other blueprints without a direct reference. It allows you to call a function without locking yourself directly to a single blueprint that you are casting to.
As an example, when someone overlaps our box collision, we would like to call the event “Bingo”.
Why would you want to use the Blueprint Interface method rather than the old casting method for this? There are two main reasons. With casting, you lock yourself to one single blueprint, in this example, the third person blueprint. With the blueprint interfaces you can call the Bingo fuction to any blueprint in the project.
The second reason is because every time you directly reference a blueprint, you link them together. This means, when one is loaded the other one is loaded, regardless of if it’s being used. Although this may not be as big of an issue with modern day computers, when you have thousands of linked together blueprints, it will slowly start to build up so this will help with efficiency.
So why would you use Bluprint interfaces?
It allows you to send messages to multiple blueprints without a direct reference
It prevents hard referencing, decreasing memory usage.
Alright, how do we use them?
You can create a new one by right clicking in your content browser, going to Blueprints and then selecting Blueprint Interface. This is where you can create all of your functions. They work the same as a normal function, where you can add input and output variables.
Once you have created a function, you can then add it to any blueprint you want. All you have to do is jump into the blueprint, in this case the “third person character”, then go over to class setting, click add interface, then add your interface.
Now after you compile, you can see all the interface functions you implemented on the left hand side, under “interface”. You can now right click them and implement the function, or just right click in the events graph, type in the name of your function and bring in the event.
If you made a function with an output in the interface, it will be greyed out. To bring these functions into the graph, double click on them. Here you can pass variables or certain information to the blueprint calling the function.
We have already brought in the event, so how do we call it? Say we have a blueprint with an overlap box. We have made an On component Begin overlap for our box trigger, now we can pull off the Actor reference and call our function.
Now, whenever an actor overlaps this trigger box, it will trigger the function in the blueprint - in this case, a text box that will say, “Hello”, when overlapped by a player character.
When would you use a blueprint interface?
A blueprint interface is used for the times you want to send a message to a blueprint, but you have no hard reference and don’t wish to create one.
It is possible to send message to a large range of blueprints using nodes below as an indirect reference.
Additionally you can use any node with the ability to give off an actor reference in order to send events.
Another time it is useful to use a blueprint interface, is when you want to call a function to a variety of blueprints, however you don’t know which one to send it to until the game has started.
Check out some of the other great tutorials on CGHero.