I was super confused as to when to use blueprint interfaces, and when I finally figured it out (in contrast to event dispatchers); I decided to make a quick guide on this matter because I feel a lot of the video guides out there mistake its use akin to that of an event dispatcher, which it’s not.
So first you have to know what an interface is; an interface in programming is a set of function names which you define based on a class. As an example lets say you have two classes: dog and cat. And within these two classes you want to implement a function called eat. So what the interface allows you to do is implement separate "eat"s for dog and cat. Then when you define the function itself, you do it inside of the individual blueprints themselves, in the example above you’d define the function in the dog as “eat dog food” and for cat “eat cat food”.
Then lets say you want to send data from one class to another, meaning in this case dog to cat or vice versa, you need to use a message to do so, and this is because they both use the same interface. If only one of the classes uses the interface then you’d simply use a reference you created to call the function. Remember according to https://docs.unrealengine.com/en-US/…ces/index.html , the two criteria for Blueprints to communicate via an interface is if:
- 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.
I’ve implemented a little demo to show how this works; here I have a YellowBorderCube in my world whose reference is defined by an inherited version of ThirdPersonBP through the details panel via the world outliner. So I’ve gone ahead and made a Blueprint Interface (BPI) and the only function I have in it is FunctionInside. And when I defined it, I defined it to simply lift the cube up in the Air 50 cm. This is in the targetBP (receiver). In this Blueprint I set the BPI inside of the class settings.
And in my working BP (sender); I have this:
Way (2) is simply put if I set the BPI in my class settings for MyCharacter BP, and I would have my own version of FunctionInside implemented in MycharacterBP (this method is called sending a message). And way(2) is simply referencing the function from the reference the normal way you would with any reference. Realistically, knowing this opens the door to understanding function libraries, and macro libraries.