How to Create an Interaction System in Unreal Engine 5 | UE5 Interaction Tutorial

Estimated read time: 1:20

    Learn to use AI like a Pro

    Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.

    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo
    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo

    Summary

    In this tutorial by HALbot Studios, the focus is on creating an interaction system in Unreal Engine 5, designed for developers to effortlessly interact with items in their game. The video covers the step-by-step process of setting up Blueprints and interfaces to enable interaction capabilities, laying the foundational work for more complex actions such as opening doors or turning on lights. By the end of the tutorial, viewers are able to implement a basic interaction system where interacting with an object makes it disappear, setting the stage for further development.

      Highlights

      • Start by creating a new folder for Blueprints and interfaces to organize your project 🎥.
      • Learn to create an interface in Unreal Engine, which is key for communication between elements 📡.
      • Set up a line trace to detect when an interaction occurs - this is essential for the system to work 📝.
      • Assign an interaction button to trigger the interaction system easily 🎮.
      • Test your setup by making an item disappear when interacted with, using simple debugging cues 🔧.
      • The tutorial is aimed at beginners and provides an easy introduction to interaction systems in UE5 💡.

      Key Takeaways

      • Learn to create a basic interaction system in Unreal Engine 5 🎮.
      • Understand the use of Blueprints and interfaces for communicating between elements 🧩.
      • Master the line trace technique for detecting interactions 🔍.
      • Develop your own interact button to perform actions in the game 🚀.
      • Use this foundational technique for more complex interactions, like opening doors 🚪.
      • Perfect for beginners looking to enhance their game development skills in UE5 📚.
      • Hands-on experience by creating your own items to interact with 🤖.

      Overview

      Welcome back, builders of the gaming world! In this thrilling tutorial, HALbot Studios takes you on a journey to create a basic interaction system in Unreal Engine 5. This video is perfect for those ready to take their game interaction to the next level. You'll start by organizing your project with Blueprints and interfaces.

        Dive into the technical details by setting up a line trace, a crucial element for detecting player interactions. This line trace system allows you to pinpoint exactly where an interaction occurs, making it an indispensable tool for your future Unreal Engine projects. Whether you're opening doors or flipping light switches, this technique will have you covered!

          Finally, the video wraps up by guiding you through testing your system. With just a click, you'll make objects disappear and check the efficiency of your work with debug features. It's a fun and straightforward way to get hands-on experience and prepare yourself for more complex game development challenges.

            Chapters

            • 00:00 - 00:30: Introduction and Purpose of the Interaction System In this chapter, the focus is on creating a basic interaction system. The concept is introduced by explaining how to approach an item in a digital environment, use an interaction button, and perform a specific action such as making the item disappear. This basic system serves as a foundation for more complex interactions, like opening doors or turning on lights.
            • 00:30 - 01:00: Setting Up the Project and Creating Interfaces The chapter titled 'Setting Up the Project and Creating Interfaces' focuses on the initial steps in organizing a digital project. It begins with creating a structured environment within the project's content folder. Specifically, a new folder named 'Blueprints' is created, followed by another sub-folder named 'interfaces.' These steps are fundamental in setting up a framework for interacting with various project items and elements.
            • 01:00 - 02:00: Creating the Interaction Blueprint Interface In the chapter titled 'Creating the Interaction Blueprint Interface', the process of developing a fundamental interface for communication between blueprints is introduced. It emphasizes simplicity and serves as an introductory guide for those unfamiliar with building interfaces. This interface is particularly useful for facilitating interactions between a character's blueprint and the interactive items within a project. The chapter promises to explore basic methods, providing a starting point for developing these essential communication tools.
            • 02:00 - 03:00: Building the Line Trace Function In this chapter, the process of creating and utilizing a blueprint interface for interactions is introduced. The user starts by right-clicking and selecting blueprint, then proceeds to blueprint interface, and names it 'BPI interaction'. Although there is an existing function, the chapter demonstrates how to rename it according to the user's preference, showcasing the practical steps involved in setting up blueprint interfaces in game development.
            • 03:00 - 05:00: Implementing the Line Trace for Interaction The chapter focuses on implementing the line trace for interaction in a project. The main task described is simple, as stated in the transcript. It involves making minimal changes, with all necessary actions having been completed up to this point. The next step is to build on this implementation. Users are advised to close the current task and return to the content folder to explore the first person character setup for future development.
            • 05:00 - 06:00: Debugging the Line Trace The chapter titled 'Debugging the Line Trace' introduces the concept of a line trace in the context of digital debugging or programming. The author discusses a preferred method for implementing a line trace by demonstrating how to create a new function named 'line Trace.' For those unfamiliar, a basic overview of what a line trace entails is promised, ensuring that both novices and seasoned developers can understand the concept and its application within the given context.
            • 06:00 - 09:00: Checking Interface Implementation for Interactable Objects The chapter discusses the concept of interface implementation for interactable objects in game development. It explains the utility of drawing a line from one point to another, which is a common feature in games. The transcript mentions using a function called 'Line Trace by Channel' to achieve this functionality.
            • 09:00 - 19:00: Creating and Importing 3D Models and Materials The chapter explains the workings of a line trace in the context of 3D modeling, specifically emphasizing the need for a start and end point. It describes the process of using a first-person camera to determine these points, highlighting that the line trace cannot be directly connected without specifying these locations.
            • 19:00 - 23:00: Adding the Interface to Our Item Blueprint The chapter focuses on enhancing an Item Blueprint by integrating a new interface. Initially, the chapter describes the starting point, emphasizing the retrieval of a camera location necessary for proceeding further. The speaker suggests using the G World location to establish a starting point. Subsequently, the chapter hints at a more complex discussion around setting up an endpoint, suggesting further steps and considerations needed to be taken.
            • 23:00 - 27:00: Testing the Interaction System In this chapter, the focus is on testing an interaction system. The approach involves using a 'get forward vector' method to determine the direction in which the camera is facing. This direction will be crucial for the interaction system as it dictates the path or orientation to send signals or interactions from. Understanding the length or extent to which this interaction needs to occur is also highlighted as a necessary aspect of the testing process.
            • 27:00 - 30:00: Destroying the Actor Upon Interaction In this chapter, the concept of destroying an actor upon interaction is explored. The discussion begins with the necessity of defining the length of a line trace to ensure it doesn't run indefinitely. To achieve this, a length variable of type float is introduced as an input parameter for the line trace. The chapter suggests using the forward vector to calculate and manage this functionality.
            • 30:00 - 31:00: Conclusion and Future Enhancements This chapter discusses the procedures for multiplying and converting values to floats within a system. It emphasizes an easy method where one can drag and drop values to automatically convert them into floats. Another approach is outlined, where a user can manually right-click and change the values to floats. The chapter implies a user-friendly and flexible system for handling data conversion tasks, allowing for both automatic and manual methods.

            How to Create an Interaction System in Unreal Engine 5 | UE5 Interaction Tutorial Transcription

            • 00:00 - 00:30 welcome back everyone in today's episode we are going to be creating a simple interaction system so that we can walk up to an item press our interact button whatever that might be and then we will be able to interact with an item in this case I'm just making that item disappear but this is going to be the base for our entire interaction system which will allow us to do a bunch of things like open doors um turn on light switches uh
            • 00:30 - 01:00 just interact with items things like that so let's get started the first thing that we're going to do back in our project is let's um let's go to our content folder and let's actually create a new folder and let's call this Blueprints and then inside of that we're going to create another folder and we're going to call this interfaces
            • 01:00 - 01:30 so this will be the first interface that we're going to create um if you've never created an interface before it's pretty simple um this is what we're going to use to communicate between our blueprints so we need a way to um communicate between um our character's blueprint and the items that we're going to interact with um now there's a few different ways that you can do this um I'm going to show you just kind of the most basic way to start out with so um we're going to
            • 01:30 - 02:00 right click here go to blueprint and click on blueprint interface and we're going to call this BPI interaction and let's open that up and inside of here um we are going to we don't really have to create a new function because they already have one in here so I'm just going to rename this uh
            • 02:00 - 02:30 interaction and that is all we have to do uh very simple now we are going to add on to this um but for right now this is literally all we need so we can close that and now let's go to our um let's go back to our content folder characters and let's open up our first person character and we are going to um start building out the things that we need to
            • 02:30 - 03:00 make this interaction work so the main thing that we're going to need here is we're going to need a line Trace now there's a few different ways that you can do this um I'm going to show you the way that I like to do it um and that is just to create a new function here and we're going to call this line Trace um and if you've never use the line trace or if you don't know what a line Trace is um I'll just give you kind of a very basic overview uh a line Trace
            • 03:00 - 03:30 allows us to very simply draw a line from a point um to another point and it then allows us to just figure out what we want to do with that um so these are very common in games this happens all the time and um we're going to go ahead and create one so um out of here we are going to drag out and just type line Trace by Channel
            • 03:30 - 04:00 [Music] okay now the way this line Trace works it needs a start and an end point um now most people what they do and what we're going to do here is we're going to use our first person camera or our camera here so I'm going to drag that out and this is going to um help us get the locations of these so we can't just plug this directly into here because we need to actually tell it um
            • 04:00 - 04:30 specifically what uh point we're starting from because this is just a camera and we need to actually get a location from here so what we can do is we can drag out and type G World [Music] location and that will be our start and now to get our end this is a little bit more complex um what we want to do is we want
            • 04:30 - 05:00 to we need a direction for this so what we can do is we can do get forward vector and that will tell us okay we're we've got our camera here and we want to know which way we're facing and then that's going to be the direction that this is going to send out um now what we also want to do we need a um we need to know how long this
            • 05:00 - 05:30 line is going to be because if we didn't have a distance we would just shoot out a line for my camera and it would just go infinitely so we need to Define how long the line is going to be so I'm actually going to click on line Trace here and we're going to add an input and that input is just going to be called length and it is going to be a floats [Music] um now out of our forward Vector we need
            • 05:30 - 06:00 to multiply we need to multiply this with our length so um very simply we can just drag into here and it will automatically convert this another way that you can do this um is you can right click on this uh or right click right here and then you can change this to a floats um but I'm just going to drag this in here that's just going to automatically convert that to a float so we're
            • 06:00 - 06:30 multiplying a vector times a float here and now we need to um so again this is getting the um Direction essentially but we also need to know the location as well so what we can do is we can actually add this together so if I type add then I can add this with this and that will be our end
            • 06:30 - 07:00 point all right so let me just clean this up a little bit straighten things out and that should be good okay so um actually you know what let's also do something else um this is totally optional but this will just make things a little bit cleaner um I'm going to click on the draw debug type here I'm going to drag out of that and if I just drop this on to line Trace there it's going to
            • 07:00 - 07:30 automatically create that um input for us and you'll see why we want to do that later um instead of me trying to explain that I'll just show you in a bit so um the next thing that we want to do here is uh we want to drag out of out hits and we're going to click on break our hit results there and then if we click this drop down box we're going to get all these different things here
            • 07:30 - 08:00 and um the main thing actually before we do this let's um let's rightclick um or sorry just go back here and let's add an output and this is let's call this hits actor and the type um will be actor you just type in actor and then it's going to be this very first one just the regular actor and then it's going to be
            • 08:00 - 08:30 an object reference so that gives us a return node here and we can just plug this up like that and then very simply we're just going to drag out of hit actor here and plug that into that just collapse that to clean it up and that is pretty much all we need to do for our line Trace so I'm going to go ahead and close that and now back here um we need to
            • 08:30 - 09:00 first of all let's create a new um input action because we need an input action for whatever our interact key is going to [Music] be so let's uh let's just copy run contrl d i a interact and then let's go back here and we're going to add a mapping
            • 09:00 - 09:30 it's going to be uh I a interact and then whatever you want your interaction key to be here so for me I'm going to make mine the letter e so I'm just going to choose e but you could choose F or whatever you want save that and close and now let's do I a interact okay so now we have our interaction here
            • 09:30 - 10:00 um so what we want to do this is when we press our interacts button we want to run that line Trace so out of started here we can just type uh line Trace get our function that we created and um we need a length for it here so um I'm going to do two
            • 10:00 - 10:30 50 um you can kind of experiment and see what works for you uh 250 anywhere from like 250 to 350 is usually pretty good um if you notice that in the game you are you know farther away and you want to be able to interact you might want to increase that or decrease it whatever you want that's totally up to you and then um this is why I added that input there for the draw debug type this way we can just very simply choose this is
            • 10:30 - 11:00 just for debugging so like if we choose for duration here let's just test this out and see what this looks like so if we compile and save go back here and hit play now when I hit e you can see exactly what that line Trace looks like so I press e it it starts the uh line from our camera and it ends at 250 units away um if we hit something that has
            • 11:00 - 11:30 Collision you can see it kind of gives like a little red dot there at the end so you can see exactly where it uh where it hits so that's very useful for just debugging and making sure that things work especially um if you hit something and it doesn't have Collision a lot of times that will be the case that it might not be working so um it's always good just to be able to quickly be able to debu that and check that it actually
            • 11:30 - 12:00 isit hitting what you want to hit there okay so what we want to do now is we want to check if this line is hitting something that um specifically has that interface that we that we created because what we're going to do is we're going to add that interface to our item and then that will allow us to uh know if we actually hit
            • 12:00 - 12:30 that so let's drag out of our hit hit actor and we want to type something called does object Implement interface and this is a built-in function that will allow us to then choose an interface so we want to choose BPI interaction and let's get a branch uh just by holding B and clicking go ahead and hook this
            • 12:30 - 13:00 up and um we could just plug this directly in here but um just for safety sake let's do one other thing uh let's type is valid and let's click on this one that the the one with the function there and let's just check to make sure that the object is valid as well um this is just a little safety just to make sure that
            • 13:00 - 13:30 it well that it is valid so let's uh type out of here um this is a common thing that you might want to know as well if you want to check two things um on your branch here um instead of having to like do this and then um you know also doing another Branch here what you can do is just type and Boolean and that will allow us to check two things here so now if uh if this and
            • 13:30 - 14:00 this are true then we will do something [Music] here okay so what we want to do here is um if this is true we can drag out of here and we can type interaction and then you'll see this interaction with a message that's what we're looking for now interaction I'm typing interaction because
            • 14:00 - 14:30 do uh if we go back and look at our interface that's what I named this function so if you named your function something different that's what you would type but um whatever you typed for that that's what you'll be looking for and you want to make sure that it has that um little envelope on it there now we we need a target for this the target is going to be the hit actor so we can just drag that into there like that
            • 14:30 - 15:00 compile and save and that is pretty much all we need to do so now what's going to happen when we hit our interact button here it's going to fire the line trace and it's going to check is this object valid and it's also going to check if this object um implements this interface and if it does then it's going to call this now this might be a little confusing um if you have interview used an interface or you are a little
            • 15:00 - 15:30 confused what's going on um this will make a little bit more sense in the next part here so for the next thing uh let's go back to blueprints let's create a new folder and let's actually create our item so let's call this um uh let's call this interaction actors so these will be things that we can actually interact with and let's do a new blueprint and we'll just call it
            • 15:30 - 16:00 BP item and let's open that up um okay so this is going to be our our actual item um so let's add a static mesh okay I've got something that I made for you guys that um it's completely free um you can check the link in the description to download this um this is uh this actually comes from a
            • 16:00 - 16:30 um an asset pack that I created here and I'll leave a link for this as well if you want to check this out um this is just an asset pack that I sell but I've got a bottle from here that I'm going to just give you guys to use um completely free but if you want to check out the full asset pack um you can check it out here and uh if you want to support me and get some assets for for your game you can um check this out um but if you
            • 16:30 - 17:00 want to just use this um this item you can download it and um when you download it you'll get these files right here so we're going to import these into our um project here so what you can do if you never imported anything it's very simple um we can just go to our content and let's create uh a new folder let's call this meshes we're going to create a few
            • 17:00 - 17:30 different folders actually we're going to create one for meshes one for [Music] materials and one for [Music] textures all right so first of all our mesh uh let's go back to here and these fbx files these are our meshes so we're just going to
            • 17:30 - 18:00 drag these in like this um you can leave everything default here just import [Music] those and you can see that it actually created a material for us um that's fine let's uh let's actually just move this to materials just to keep things clean and um close that and then let's go to textures
            • 18:00 - 18:30 and then back here and let's highlight these textures and drag them in here okay now I'm going to close that and let's go to our material that it created for us um if it didn't create a material for you you can very simply just right click and um click on material there and just name that for whatever you want but it just created one for us so let's open that up and we're going to get this I'm just going
            • 18:30 - 19:00 to delete this cuz we don't need that and I'm going to grab our textures here and just drag those in and we've got three textures here so I'm just going to kind of organize them like this um our first one is going to be our color so out of RGB I'm just going to drag that into base color um our next is our normal so RGB
            • 19:00 - 19:30 we're going to drag that into normal and then our third one um this one is set up to where if we open this up um this one has different things kind of built in to the different RGB colors here so um the way this works this you might see this on other materials this just saves a little bit of room by combining these together um whereas some
            • 19:30 - 20:00 materials might have um a different texture for the metallic a different texture for the roughness and so on this just allows us to combine those into one thing so what what we can do here is out of b um that is our metallic and then G is our roughness and then the r is our ambient occlusion
            • 20:00 - 20:30 um oh and one other thing that we need to do we need to open this texture and we need to uh change where it says srgb here we need to uncheck that and then when you do that you're going to get an error here that's because this needs to be set to linear color and let's apply that save so now if we go back to our mesh
            • 20:30 - 21:00 and look at our um at our mesh here and we have the correct materials now um one other thing you want to do here you can see how that looks invisible there so um back in our material um if you look right here it says two-sided we want to check
            • 21:00 - 21:30 two-sided okay so check that apply and save and now that will have an interior there okay so now let's go back to our item and our static mesh we can set that to the bottle compile and Save
            • 21:30 - 22:00 and um let's uh let's do this I'm going to click on this wall here and I'm going to hold alt and then just uh drag out that will just make a copy and I'm just going to use this as like a little shelf so I'm going to go over here and hit um reset here so that we just have a little shelf here just to set this on so let's go back to um our blueprint
            • 22:00 - 22:30 folder and grab our actual item drag it out here and now we have a little something to set there okay now I can't just um interact with this right now because um we don't have any way of knowing if this is actually hitting that I mean you can see that our line Trace is hitting it but um if you remember in our first person character we're checking if um if the
            • 22:30 - 23:00 object that we hit actually has this interface and this item does not have this interface so we need to add it so if we go up here to class settings and if you look over here under implemented interfaces uh we can type our interface that we created BPI interaction now you'll notice if we go to our graph here we can delete all of
            • 23:00 - 23:30 this um over here under interfaces we have this interaction and if I double click this it actually gives us an event so now what this interface allows us to do uh when we hit our interact key and it fires the line Trace it's going to send out a message to fire this event and any blueprint that has this
            • 23:30 - 24:00 interface and then has this um event here is going to fire and now we can do anything out of this that we want um so for right now let's just do a print string and let's just type interactive just to let us know that that is actually working so now if we go back here and we
            • 24:00 - 24:30 play from here um if I hit off to the side nothing happens but if we actually move our cursor over the item and hit e then you can see up in the top left corner it says interacted so that is really the basis of the way the interaction Works um now there's all kinds of things that we can do from this um once we create an inventory system we could add
            • 24:30 - 25:00 this to our inventory um we'll create an inspection system that we can start inspecting um but for right now let's just do something really simple like destroy this actor so when we interact with it we'll just make it disappear so we can do that just by dragging off of here and just type uh destroy actor and maybe we also do like a small delay type delay and we'll just do
            • 25:00 - 25:30 like5 seconds compile and save so now when we interact with that um it should disappear in a half a second so I'm going to press e and there we [Music] go so that is pretty much it um that is kind of the start of our interaction system we're going to build off of this there's going to be a lot that we're going to do with this but this is just
            • 25:30 - 26:00 kind of the the base start for this and um is going to uh give us a lot of things that we're going to be able to do so I hope that was helpful um if you guys have any questions as always please let me know if you did find this helpful please leave me a like and um subscribe and uh I will continue making these videos all right thank you guys so much and I will see you next time