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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey how's it going everyone my name is brandon clements and welcome back to another video here on glasshand and i am excited to show you this one principle of programming that took me years to understand and i'm not kidding like i you know i've come a long way in my programming journey i used to be the absolute worst at this stuff and that's why i'm making these videos is to try to help those artists who are transitioning into programming who want to create games or experiences that's why i'm making these videos today so the last time i left you guys i left you with some pretty hard references in that direct communication video and what do i mean by that um well the switch had to directly talk to another class that was the hidden door and that that may not seem like a big deal and it may not you know for your experiences for your small prototypes whatever it may be it may not be a big deal and modern computers can honestly handle a decent amount of references hard references like that but what's going to happen when you create your experiences further down the road it's going to be really hard to make changes to uh to anything like that because you're basically running into a principle in computer science that in computer programming that's kind of known as coupling so your classes basically they depend on one another and it's slow and it's very bad to prototype you know once you get to a certain scale and a lot of tutorials especially unity tutorials may have you access like a game manager and that game manager may have like a ton of methods or variables and you're constantly having to hard reference that game manager and before you know it everything is tied together and you can't pull it apart and like i said that may not be a big deal to you right now but i promise you one day if you keep continuing down this road that i've continued down it's going to be really hard to make changes to your experience or to your game because of that tight coupling so what i'm going to show you today is interfaces blueprint interfaces now interfaces are in c sharp they're in java script you know there's a lot of different uh interfaces for programming this is kind of like a principle but it's basically a way for you to promise behaviors to objects it's your promising behaviors but you're not specifying any implementation details what the heck does that mean i'm sure you're thinking that right now and it took me forever literal years for me to understand the importance of this and so if you don't understand this just watch the video over again um i'm about to show you some really cool stuff before i just make my interface just go crazy okay so let's take a look at where we left off last time uh if our first person character walks into this volume then this uh door opens here well this time i want us to walk up to this switch press e and then have that door open but we're gonna do it without hard references and if we show you the references right now for example if i go here and say reference viewer this shows us our hard reference tree so basically this is our blueprint right here and then it connects to this hidden door it also references our first person character and then uh you know it references this little cube that we've had that's like a separate object okay and if we click on our first person character you can see that it's referencing the switch okay so this can get out of hand pretty pretty quickly uh trust me on this if you're building a large game with all these hard references so i'm going to show you how to decouple all of that by right clicking go to blueprints go to blueprint interface and we're going to call this bpi for blueprint interface underscore interact okay and then we're going to double click we're going to open this and i'm going to create this function here it already creates this a new function but i'm going to call this interact okay compile save and that's literally it so this is um our interface but we're not specifying any implementation details we're just saying we're gonna pass along something called interact to those who have who are implementing this interface it will make sense to only those objects and then i want to do something else we're going to go to project settings and we're going to go to input and under here i'm going to create a new action mapping and this is going to be our interact action okay and in most games i would assume that's going to be e on the keyboard for pc games if you want to add another uh like gamepad button you can come down here gamepad and you could say you know it's like face button top or something like that so that would be um it's been a long time since i've played playstation it's triangle right and on xbox it's uh why it's been a long time anyways that's what that would be so that's how you can do it in unreal engine with the input mappings okay so i want to go to our first person character real quick so let's open our first person character and we're going to start putting in the action mapping that we just created so if you right-click and you say uh interact action we're going to go ahead and get this event so once this is pressed something's going to happen right well i want to come up to our class settings and here i want to implement our bp underscore interact so this is where we implement our interfaces now you have to click compile to be able to access any of this okay very important it's something i always forget about so i want to basically come over to our components here and uh actually this capsule component i just want to get this i'm going to drag it into our event graph right here so we're going to go is let's see i think overlapping and get overlapping actors yes this is what we want because i want to have uh this class filter here so we're basically just going to check any actor so whatever our capsule component which is on our first person character you can see this giant capsule whatever it's overlapping we're going to make sure it's an actor okay and we're going to get those actors and we're going to do a for each loop okay and we're going to make sure each of these actors that we're overlapping with once we press this button is implementing our interface okay so let's loop through all these and make sure does it implement our interface and that's our bpi underscore interact yes or no we're going to branch from that which is a condition inside of unreal engine as our branch okay grab that execution wire and then if it does implement we want to fire off a message that says interact not that guy we want the message the easiest way to you can see i'm failing right now the easiest way is to get this array method and just say interact and here we go this is our message so if it implements that let's go ahead and interact i'm going to clean this up by double clicking on the wire i may pull this down a little bit just so this is legible and we're going gonna do that and we're gonna break okay so we're gonna keep looping through whatever we're overlapping with and make sure that it implements our interface okay so that's a pretty easy way of getting our action mapping and we can select all this and uh hit c and we're gonna say interact action okay so that's our logic for that all right so just to review one more time we're going to get our input action which is e on the keyboard we're going to make sure our capsule component is overlapping something we're going to throw all of those items into an array and we're going to make sure that those items implement the interact interface and if so then we're just going to send that message to them and we're going to say hey we're going to do that thing that we promised that we were going to do and it's going to keep doing that until it breaks all right so it's going to loop through all our actors and then it's going to break and it's going to stop okay so that's a really cool way to for each loops right you're figuring out i had the power of four user loops in this video okay great so let's go ahead and save that and then we're gonna open our blueprints and we're gonna start with our switch and this is what we had last time and this was all fine and dandy but like i said at a scalable um in a scalable game or uh or experience this isn't going to work for us it's not going to be good enough i'm going to go ahead and delete these references okay okay so now we're back to square one with our switch but we're going to start implementing our interface so let's go to an interface let's say sorry not interface it's bpi underscore interact so we're interacting with this thing it can be anything that we're interacting with that's the power of this then we're going to implement the event after we compile very important go ahead and implement this event so we have an event called interact and you can see that this is a interface judging by this icon here that's our interface icon i also wanted to show you that you know this is the message that we're sending out okay i like the icons because it tells you that hey this isn't just any ordinary function this is a giant message that we're sending out that has any actor that implements this interface okay so once we do overlap this item and we're hitting e on our keyboard to interact we need to make sure this box that we created so if the player is standing within this box we want to make sure that it is overlapping our player so we can say is overlapping actor and the cool thing with uh unreal engine is that you can pretty much get your player um information from any from any blueprint basically so get player controller character pawn we're going to get our pawn so we're going to make sure that it's the thing that we're possessing is overlapping the box we're going to make sure that we do a condition on this if it is true let's just go ahead and print string i haven't showed you guys this yet but this is the way uh you know a simple way that you can debug inside of unreal engine so now we walk up we're going to say e to interact and it says hello in the top left okay so you can make that message say anything uh you can make this say is interacting and then you would just go compile save so then if we hit play and we walk up and we hit e you can see that it says is interacting in the top left every time that we hit e on our keyboard cool so something is working things are working things are communicating this is great so what we want to do is we want to we want to target an object right so last time if you remember we stored a hard reference at on event begin play to our hidden door and then we took that variable and we said hey we want to access the open sesame function with inside of the hidden door okay we're going to decouple that and we just want to say some actor we want to send a message to it okay so let's create a variable that is our target right this is our this is going to be our target for our blueprint so we'll come over to variable type and it's just going to be a generic actor class okay we're just we just need a reference to that we're going to turn on our eyeball so it's a lot easier for us to get something from this and then we want to say interact and we're going to send a message to our targeted generic actor and this is still okay for us to do this is just a reference to anything it could be anything in our level alright so this is still allowing us to decouple and we're going to say hidden door once we hit that eyeball that allows us to have the reference in our editor which is really super handy okay so with that stored we're gonna go ahead and hit compile and save and then let's go to our hidden door on our path to decoupling inside unreal engine we don't need open sesame anymore we're going to go ahead to our class we're going to implement the interact we're going to compile first implement our event and then go ahead and move all right so let's compile save and we'll come back in we're going to overlap we're going to hit e and there we go that's pretty awesome right we don't have any hard references to anything so now this switch is not just a door switch it's a switch to a light bulb it's a switch to a ceiling trap door i can't think of anything besides lights and doors it could be anything it could be anything this could be something that you have to hit on a command console to progress to the next level i don't know anything your it could be whatever so it's now just a generic switch and not a hidden door switch so now the coolest part of all this is if we right click on our switch and we view our reference viewer you can see the only thing here is the interact alright so as you go and you create your games and your levels and your experiences you won't have a massive list of things that it's hard referencing to in certain levels and certain blueprints whatever this is decoupling everything so this is this is as far as it goes it just sends out an interact message and it to anything that is implementing the interface it will do something uh so let's look at the hidden door the reference viewer here same thing so now if we right click on our first person character we go to reference viewer this is as far as we go in terms of hard references we are just loading into memory bpi interact we're not going to load in all these other blueprint classes into memory when we load our character this is going to make things so much faster for your games and experiences uh man interfaces are the bomb like you just create an interface for interact you make an interface for whatever else and you just start implementing them to different classes and you're now decoupling everything which is great this is awesome and it took me years to figure this out guys it took me years to figure this out and you figured it out today uh hopefully early on in your journey so that you can create some amazing experiences in unreal engine so guys if you like this video please give it a like you know it's a youtube video so i have to tell you to do that now it really does help this video get seen by many others hopefully it helps other people if you have any questions please leave them in the comment section below i do actually answer questions i really do read everything so i appreciate you guys we'll see you in the next one take care
Info
Channel: Glass Hand Studios
Views: 99,377
Rating: undefined out of 5
Keywords: unreal engine, learn, blueprints, coding, programming, game, game design, introduction to unreal engine, learn blueprints, unreal engine 5, unreal engine 4, it took me years to learn this simple principle, blueprint interfaces, blueprint interface ue4, blueprint interface tutorial, motion graphics tutorial, unreal engine 4 blueprint tutorial for beginners, blueprint tutorial, blueprint tutorial unreal engine 5, beginner unreal engine 5, I Struggled With Blueprint Interfaces for Years
Id: m9416Fi-PJw
Channel Id: undefined
Length: 16min 48sec (1008 seconds)
Published: Tue May 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.