How to Use Blueprint Interfaces In UE5.1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I have found the light of the blueprint interface and soon you will too! Never will you have to use those cursed castings ever again! This will make your old sloppy code not only 100 times more readable but also significantly faster on contemporary hardware. You might be asking "what is this blueprint interface that you're raving about?" Well a blueprint interface is nothing more than a collection of definitions that your blueprints can use. They lack any definition other than the inputs and outputs they allow any blueprint that interfaces with them to call an event that runs on all other implementations of the function. With that said let me show you the light of the interface. One last thing before we begin the project I will be using is linked in the description though it is not strictly needed to follow along. I will also be in level one in this level one level. To get started we need to create an interface to do that we should go to the folder named blueprints then interfaces. Next we can right click in the content browser then hover over blueprints blueprint interface. Finally give it a name and hit enter. Now we can double click to open it. When we do so we will see the normal blueprint editor with one major difference. This blueprint is considered read only that is because a blueprint interface does not and cannot have any code it just holds the event inputs and outputs. Other major differences with an interface is that they cannot add new variables, edit graphs or, add components. To start we will rename the function named a NewFunction_0 to Pickup. Then we will add a generic object reference and we will call it PickupObject. Next we hit compile and save. Now that we have created the interface we need to add it to the actors we wish to use it on. For this example it will be our first person character found in content import FirstPersonBP blueprints. Then open the first person character and go to the event graph. Next to add the interface to the blueprint we need to go to class settings then under interfaces click add and search for the interface. Then you will see it under pickup now we need to hit compile to be able to use the interface. Next we will do the same thing for the object we wish to pick up it can be found in content blueprints fragment and it will be called SoulShardPickup open it then do the same thing as last time. Class settings add pick up compile and save. Now that the actors know about our interface we can implement it. First in the character controller we can right click pick up and select Implement event. We can then replace the custom event SoulFragmentPickup with Pickup. Then from pickup object we will add an equal equals block and set the second value to SoulShardPickup then we will add a branch. Connect these up and the true will go into our old code I'll just make this look pretty. This allows us to call the pickup function on any object just by testing for what we picked up saving us for making hundreds of custom events for each pickup object. Now in the soul Shard pickup class we need to remove the cast node in the custom event node next we drag from other actor and select pickup message. Then for pickup object search for SoulShardPickup finally reconnect the destroy actor node to the pickup message. Now compile everything and test if it worked by running down the hall into a fragment it should increase the number in the top left by one and the fragment should disappear now that's working. Interfaces with outputs, now that we have the basics of interfaces we can move on to more complex ones. Now make a new function in our pickup interface and call it print object next add an input of an object reference and name it object then add an output of type string and name it name next press compile and save. Then we can go back to the first person character and double click on print object. Here we can Define the local definition of this function we will do that by dragging from the object and selecting get object name. Then drag the output to the output that allows us to drag it out in the event graph and connect it to the execute path of the pickup function in the first person character I'll do that before the branch. Then for object we can use the pickup object finally with the output of this function we can drag that into a print a string in order to print the name of the object that we picked up. Compile and save and then last we can test it the same way we did with the other interface test by running down here I'm picking these up. And you see up in that top right there's a SoulShardPickup that's coming from our blueprint interface. Hopefully blueprint interfaces are not so scary anymore. If you want any other help into how to use ue5 a playlist of all my ue5 videos should be showing up and if you could please don't forget to subscribe and ring the bell for more weekly ue5 content. Have a great day and bye for now!
Info
Channel: Savage Games
Views: 11,986
Rating: undefined out of 5
Keywords: Game Dev, Unreal, how to, tutorial, UE5, help, UE4, landscape, US5.1
Id: dZZ5QgJWAl8
Channel Id: undefined
Length: 7min 35sec (455 seconds)
Published: Sun Jan 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.