BP interface functions useless?

What is the point in creating a function in the Blueprint Interface if you have to set its custom functionality individually in each separate blueprint

Because it allows you to communicate with whichever blueprint implements that interface and have appropriate functions. And by the way, I think you should read up on Object Oriented Programming (OOP), it will help you understand better.

For example :

I have 3 different kind of objects, a human, a wall and a mirror, human and mirror are shoot-able, the wall is not.
The shoot-able objects implement an interface called IDamageable. In the interface, there is a function named as Damage. Damage function for human is spawn blood and mirror is spawn broken glass pieces.
When I shoot at the human, I want him to bleed and when I shoot at the mirror, I want it to spawn broken glass pieces.

Assume we use line tracing to detect what object we kind and we are shooting at the human, so how do we determine whether it is wall or mirror or human? We can use casting, if cast succeed, it means the object we are shooting at is human, then we proceed to spawn blood spilling out of his head, else, it is something else.

Now imagine we have 1000 objects, 700 of them are shoot-able, 300 of them are not. Casting them one by one is not really a good idea right? (unless you enjoy tedious work)

So, we test whether the object implements the interface IDamageable, if it implements it, it means it is one of the shoot-able objects, we can then proceed to call it’s Damage function and it will do it’s magic, spawning the correct effects.

Note, this is just an example of how you can use interface, and please correct me if I am wrong :slight_smile:

This is the right answer…. Anywhere you want to abstract the type your current context is interacting with…. Another example would be animation blueprint needs data from owner but what type is the owner? Doesn’t matter can be player or npc as long as they implement the appropriate interface the animation blueprint needs…. Casting to specicific type is considered tightly coupling and should be avoided… .interface defines contract between implementer and caller without the need to know who the implementer is and can be used in loosely coupled solution

Ah okay, sorry. I’m not really good at explaining stuffs :stuck_out_tongue:

No… I meant your answer was the right answer! Just wanted to add to it :stuck_out_tongue:

If you want to just write reusable functions you should look at the function library

hehe okay, thanks :smiley: