After a couple of days struggling with Blueprint Interfaces (BPI), I thought I’d post and see if the community can help me out. While using these interfaces I’ve been encountering crashes, so I’ve found it hard to test for myself. A few questions then!
1) Is it valid to store an instance of a BP that implements a BPI as a BPI variable on another BP?
I’ve been using actors that spawn other actors on Begin Play, and store them as the BPI they implement. Later, the original actors use the spawned actors by calling BPI functions on them that they implement, so the spawning actor cares nought for what exactly the spawned actor is.
2) For a BP instance to call a BPI function on another BP instance, do both BP instances need to implement the BPI?
I ask because the “Calling Interface Functions on Other Blueprints” section of .unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Types/Interface/UsingInterfaces/index.html indicates that must be so. However, that’s really not how I intend to use BPIs; I’m imagining a player character with an array of attack actors all implementing the attack interface (i.e. an array of attack interfaces), and the player character calling “Execute Attack” on each one in turn. If the player also needs to implement the attack interface, I am definitely misunderstanding BPIs, since the player is not an attack!
If anyone can tell me if I’m on the right track with BPIs, that’d be great. Cheers!
Wow, was a tough post to read. Is it not possible to set the used interface at the blueprint level? I feel like that would be the easiest way to accomplish rather than trying to dynamically set the interface when the actor is spawned. If that’s not possible for some reason…
I would say no. I’d be surprised if it even let you.
Yes, all instances of the spawned blueprint need to implement the interface you’re trying to call. But like I said at the beginning, if you just set them to implement the interface at the blueprint level, you don’t need to worry about any of .
Interfaces don’t actually mean that the implementing BP is that interface, think of it more like a function of the BP that can be seen by all of the actors that implement it.
For example, the Attack interface defines what needs to happen when Attack is called. Some of that information needs to come from the player, such as where/when/what to attack. Therefore the player must implement the Attack interface to propagate these values to the other implementing actors of Attack, who use the info to launch an attack.
So by implementing an interface, the player does not become ‘Attack’, the player becomes capable of calling and/or receiving the attack message. Hope that makes sense!
Aha! Thank you both. I had suspected that I was misunderstanding what interfaces were about. I think I’ll have another play around with concept in mind.
Ok, i could be completely wrong now, since i already had some beer, but i think
means something like that (if i’m assuming wrong, dont hit me please ):
Lets say i got an interface BPI_Attack, and 2 BPs that implement interface, i.e. BP_AxeAttack and BP_SwordAttack.
Now when you have a variable in your Pawn of type “BPI_Attack” you should be able to assign any of the 2 attacks to the variable, as they both implement the interface.
is even more true in C++ since, unlike Java or C#, C++ has no “real” interfaces, but interfaces are classes with only pure virtual functions, which then act as BaseClass with functions to be implemented.
So, theoretically the above scenario should work, but i am away from my UE4 PC now and i cant try. Any objections?
That’s exactly what I was getting at indygoof. Unfortunately playing with BPIs started crashing my project, so I’ve left them for now; I can do the same with all the functionality put into a base class and use that as a variable to store child classes in. I just have to remember to pop a call to the parent functions/events in every child function/event, regardless of whether the function is overridden.
Out of interest, is the OP that hard to read? I thought it made perfect sense
To be fair, the documentation for Blueprint Interface is a bit ‘light’. Not blaming Epic, but the engine is still young, & hopefully, some areas of the documentation can be improve.
Additional documentation regarding Blueprint Communication is coming soon, just waiting on the green light to make it live. The documentation is similar to the Matinee How To’s and will walk you through short examples of setting up different methods of communicating between Blueprints (using Interfaces, Binding Events, Casting, Event Dispatcher, etc.). There is also a small Blueprint Communications Quick Start Guide that will touch these topics as well. Should be posted in the next week or two, but don’t hold me to that just yet.