I Struggled With Blueprint Interfaces for Years!! (Unreal Engine 5)

preview_player
Показать описание
I will admit that I struggled with blueprint interfaces for years! It took me years to understand why decoupling was so important to interactive media. Using these core programming principles, you will be able to change functionality without worrying if you will break other classes. #blueprint interfaces are so powerful and one of my favorite tools to use in Unreal Engine!

:) Comment below and let me know what videos you would like to see! Thank you!

Subscribe and begin learning with us today!

Email: brandon[(at)]glasshandstudios[(dot)]com
Instagram: @thebranclem
Glass Hand Instagram: @glasshandstudios
Twitter: @thebranclem

#ue5 #unrealengine

0:00 - 2:30 Intro to Decoupling
2:31 - 3:13 Definition of Interfaces
3:14 - 4:06 Reference Viewer
4:07 - 4:47 Create Blueprint Interface
4:48 - 5:40 Input Mapping
5:41 - 9:40 Implement Interface & Action Mapping
9:41 - 12:22 Implementing Interact Event
12:23 - 14:45 Target Object
14:46 - 16:16 Checking Our Work
16:17 - 16:48 Like and subscribe! :)
Рекомендации по теме
Комментарии
Автор

Thank you for checking this video out! In the next video I will talk about event dispatchers! Cheers guys!

GlassHandFilms
Автор

The problem with this is that you implemented the "interact" event in both the switch AND the hidden door, this means that in case the overlap event of the player's capsule fires (might happen) while standing on top of the hidden door, the player can press E and the door would open without the need for the player to interact with the switch.

The correct way of doing this is implementing another function in the blueprint interface that handles "indirect" interactions so you can send the "interact" message from the player's blueprint to the switch's blueprint "interact event" which then fires off and send the "indirect interact" message from the switch blueprint to the hidden door's blueprint "indirect interact" event.

Doing this you completely avoid the "bug" I described earlier. I hope this might help.

brunoverde
Автор

The most simple way is to add the interface "Interact" to all interactable objects, then fire a linetrace from the camera view of the player and check if it is hitting an interactable object, if it is then call the interact function from the interface (it does all the things you want the objects has to do calling every time the same function)

guystech
Автор

Just started learning UE5 and was making action blueprints for every interaction. This has saved me from so many future headaches and streamlined my game logic.

ethanbelton
Автор

Great tutorial. I just want to let it be known that having that "does implement interface" step is usually unnecessary. It was used here to basically tell the ForEach loop that it's found the first instance of something you can interact with to then be able to break the loop.

You can just call the "Interact" message function, and it won't do anything with any actors that don't implement the interface, which is one of the most powerful things about using Interfaces. Again that branch check was just to check that we ran into the first instance of an actor that implements the interface. If, for example you wanted to loop through all the interactable actors within the overlapped actor, you just need to stick a pin straight into the "Interact" message and it will trigger the interact function on every actor that has an interact function and skip the ones that don't with zero bugs or erroring out due to unexplained references and whatnot.

KyleKatarn
Автор

recently started using Unreal Engine and what you said totally blew my mind. I have absolutely zero experience in this, but by creating reusable formulas, you can make your life so much easier. It makes it easier to create NPCs, areas that repeat, objects/objectives that repeat. Pretty much anything that repeats. Thank you!

ChubbyHubby
Автор

Thank you i have been strugling with this for months, watching many tutorials and never really grasped the concept until I found your tutorial and it all came into place the best explanation out there by a mile.💯

mx-gamesdev
Автор

Best explanation of these I've seen yet. You caught me early in my journey. Thank you for likely saving me from a ton of headache later on!

SB-jxox
Автор

Also, an alternative to using interfaces is to use components. So you could create and actor component called "InteractableComponent" that you can attach to your interactable actors. And then create a delegate "Interact" in that component so you can implement it in the Actors (this is what for example box collisions do when you implement the OnBeginOverlap delegate). And to call the method interact you just call

The advantage of using components is that you could have a default implementation as well and you can abstract logic in it. For example, you could have an enhanced input action in the interactable component so you could also implement the input handling logic there. The biggest disadvantage is that delegates don't support methods with return values, so interfaces are useful for those cases.

Personally, i find interfaces an antipattern due to how often are abused. They're very useful when used to remove dependencies between modules (i.e ItemModule from InventoryModule, QuestModule from InventoryModule/ItemModule, etc). But when overused to isolate single Actors within a module (module as in collection of objects that perform a single purpose), they make things harder to debug and maintain.

Cronofear
Автор

I don't know how many videos I've watched. I really thank you very much. I'm glad to have you, my friend.

ULGENX
Автор

We usually use the able suffix for interfaces like Interact
Interactable, Deletable, Archivable, etc.

HansFriedrich
Автор

In Blueprint you actually don't have to check if an actor implements an interface before sending an interface message. You can just send the message, and if the actor doesn't implement the interface the message will just be ignored.

In C++ you do have to cast the actor to the interface class to check if the interface is implemented.

And for hard references: a problem that you didn't mention that everybody should be aware of is that, beyond just getting a massive tangle of dependencies that will make making changes to your game extremely difficult, when you use a hard reference in a blueprint it actually loads the referenced class into memory. So even if the referenced class isn't in the world yet (i.e. you have a game manager class that references unique objects in every level), those classes will be taking up RAM for the entire game session. And if THOSE classes contain hard references those objects will be loaded too, and if those classes reference... etc. This could potentially lead to your entire game getting loaded into memory at once.

Fafhrd
Автор

This is the type of breakdown I've been trying to find! I've been struggling with understanding how to properly use both blueprints and interfaces with the constant tweaks I add to evolving systems.

katelinthurman
Автор

Man. Like you I struggled with this. Watched a lot of tutorials before yours, but yours is the one that put me over the top. Thanks!

mihaiwilson
Автор

Thank you! I've been watching so many Unreal tutorials and so few of them focus on good programming practices for scalability.

Nomadjackalope
Автор

Amazing tutorial I keep coming back to this one whenever I forget.

protophase
Автор

I'm so happy I took the time to listen to this. Super useful for a casual user like me.

pseudonym
Автор

I really appreciate the approach you take in this video. It felt more like a lesson or class, which was 100% what I was looking for. You explained why you were doing each part precisely at a normal pace.

Thank you so much for this video, subbed!

Zesilo
Автор

My only extension of this (besides the bug fix mentioned below) would be to make the target actor variable an array, and implement the code to fire Interact for any objects within that array. This way you can have a switch that talks to multiple objects at once.

MNFL
Автор

@2:14-2:24 Literally where I've ended up... When there is a mess of actors combined with other game mechanics, character blueprints and player controller, all intertwined it gets really messed up. I appreciate you taking the time to put this together

MBAalrightgames