Interfaces. Cannot use message in two bp with same interface

Hello guys!
I have a question: I make interface with one function. If I add this interface in two different blueprints, then I cannot use “message” for that function in any of that blueprints. I can use just event call (with description “Target is target”) which doesn’t work. But I can use message in bp where this interface doesn’t include and it work.

What’s wrong with my interface or maybe I’m just don’t understand everything well about that?

Hey there,

sadly i don’t really get how you are trying to use the Interface. But i will just generally explain the use of an Interface, maybe that already sorts things :smiley:

An Interface can have multiple Function Declarations/Implementations. Declaration means it just Inputs and Outputs without Logic. Implementation would also have some Logic in it.

How and for what do you now use the Interface?

As you already found out, you can add Interfaces to BlueprintClasses. When done, you can OVERRIDE the functions of the Interface in this Blueprint and let the Blueprint give this Function its own Implementation.

Let’s say we have an Interface with a function called “Use”. This function has no inputs or outputs, to make it easier to follow.

Now you add this Interface to a door Blueprint. The DoorBlueprint now overrides the function and adds some opening logic to it.

Now you add this Interface to a second Blueprint. This one is for example a weapon pickup. It also overrides the Interface Function with a logic that makes you pickup the weapon.

And now? Imagine you have a line trace when pressing your E key. You trace the Door and the Weapon. Both will be returned as an “AActor” in the HitResult. Normally you would now need to Cast the AActor (HitActor) to the Door and call the “Open” function on it, or to the Weapon and call the “Pickup” function on it.

With more and more different actors you would need to cast to a lot of different classes to test if the actor you traced is of that class. This is kinda inefficient and would result in a really big blueprint function.

BUT that’s where the interface comes in handy. You can use blindly call “Use” on this Actor. IF the actor has the Interface and the Use Function overridden, it will call it’s implementation.

So you don’t need to care about casting, you just call “Use” on the Actor and if you hit the Door which has the Interface, it calls its own version of Use. Same for the Weapon and all other Blueprints you add the Interface to.

Actors that don’t have the Interface/Function will just ignore the call of course.

Yeah, I understand for what I use interfaces =)
Just as I remember, if I add interface for two different blueprints so ONLY THEY are connected between each other and I can use message from one to another. But I may use message ONLY from blueprints where that interface didn’t added.
So just this thing is weird for me…

I actually only use them for the second thing. Calling Interface Messages in blueprints that do NOT implement the Interface, but on Actors that DO implement them. Like the example i explained above.

When i want 2 Blueprints to communicate with one and another i just make sure i have a reference of one in the other .

So I need to add interface only in one blueprint where I wanna to call interface function and I can call it using message from every other blueprints, even if that interface not added into them?

Yes, only the Blueprints that you want to call the function on needs the Interface. Every other Blueprint that should call the function doesn’t need the interface.

But you need a reference of the Actor that has the Interface.

Ah, well, now, I understand. Thank you much! ^^