How to INSPECT ITEM in Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in this tutorial we will see how to make item inspection for example to inspect an object I click on the button I've chosen for inspection now I have the object here I can rotate it I can release it again we can also add sounds to it I've created a folder to store the blueprints we're going to create I've also created a copy of the first person so I don't have to modify the original let's open the character and go to the viewport selecting the camera we will look for scene this places it inside the camera if you place it outside drag it inside the camera I'm going to change its name item it will be the item will'll see in front of the camera selecting the item we have to move it I'm going to place it around here so that it's in front of the camera approximately because we will adapt it later with a variable that depends on whether the item is closer or farther away as not all objects are the same size we compile now let's go back to the folder rightclick blueprint and create an interface I'm going to name it inspect interface open it in this function I'm going to name it look at for when we look at the object to inspect and we add an input which will be the character's input player character of the type of our character which is firsters inspect in my case let's create another function I'm going to name this one interact with we're also going to add the same input you can compile this and you can close it because we won't need it anymore now let's create the blueprint that will be the parent from which we will create child blueprints for different interactable item actors rightclick blueprint class actor this will be blueprint inspect [Music] parent open it we're going to set a base mesh add a static mesh drag it here to the rout for testing purposes you can use any mesh you like I'm going to add a [Music] cube I'll make it a bit smaller here you can change its name inspect mesh for example we will also simulate physics in the class settings set the interface we created the inspect interface so that all child blueprints have this interface and perform the same actions we compile now let's go to our character to create the line trace for detecting objects we'll create it as a function I'll rename it to check look at we will need either the line Trace by Channel or the sphere Trace whichever you prefer drag the camera get World location the camera's location will be the start from the location look for add connect it to the end from the camera get World rotation from here get forward vector and multiply connect it here this bottom pin rightclick and convert it to a float set the distance at which we will interact typically 200 or 250 is common now from out hit create a break hit to see what's inside it's important to set the line Trace to the camera create a look at actor variable which will be the actor we are looking at of type actor so on one hand from the hit actor search for does implement interface if it has the interface we created the inspect [Music] interface search for a branch this is one of the conditions take the look at actor get and search for equal if it's equal to the hit actor connect this to another [Music] Branch if it's false take the look at actor set and connect it to the hit actor in The False part of the first Branch look for a set for the look at actor from this look at actor search for look at message which is part of the interface and the player character will be self look for the return node and add an output which will be of type actor rename it to look at actor connect the return node to the end connect the look at actor variable as well Place Another return node in the other set if you want to test if it works correctly in the debug you can select persistent for example to continuously see the lines colliding with the item and it's important to activate this event in the event graph in the event tick activate check Lo at go to the map and drag the parent into the scene hit play you will see this line and when it collides it turns [Music] green I changed it back to none so that the lines don't appear The Next Step would be to create the input for the keys we will use to activate and deactivate inspection go to first person input you have the default input already activated open [Music] it in the mappings add two more one will be for inspection let's create it inside actions rightclick input input action this will be inspect search for it here select the button you want to use I'll choose e for example add one more input for stopping inspection stop inspect I'll choose R save it now in the character search for the inspect input we have inspect and stop inspect we drag the look at actor variable rightclick convert to validated get connect it here search for the interact with message of the look at actor which which is another function in the interface the player character is self create another variable this one will be for the item held in the hands current item and the type should be the same as the parent we created we named it blueprint inspect parent go back to the parent create a function to start inspection which we'll call start inspect before proceeding with this function go to the event graph and search for the interact with of event do a promote to variable from the player character to have easier access here find get current item and validated get here search for start inspect the function we just created back to start inspect the first thing we'll do here is to drag the mesh and turn off simulate physics set it to false when you pick up the item it won't simulate physics search for set Collision enabled and set it to no Collision drag the player character search for Set current [Music] item the current item will be self the actor itself search for set actor location what will the location be find get player camera manager get camera location this is similar to what what we did in the line Trace add and this is the new [Music] location from the camera manager also search for get camera rotation get forward vector and multiply which you connect here [Music] right click on this pin and convert it to a float the value will be the distance at which the item will be placed in front of the camera when inspecting since not all objects have the same size it's better to promote it to a variable so that you can adjust the distance according to the item I'll read rename it inspect distance we'll set a default minimum value I'll set it to 100 for example the variable should be instance editable so that you can change it in the scene we should also disable characters movement when inspecting search for disabled input from the player character look for get player controller connect it here also search for enable input connect the player controller as well but leave the target empty the character should be in the target for disable next we want to attach the item search for attach actor to component connect it to the rest change it to snap to Target and set the rotation to snap to Target as well leave the scale as it is from the player character search for get item and connect it to the parent we compile now let's create another function for when you stop inspecting add a function stop inspect search for get player controller to allow the character to move again find disable input and enable [Music] input connect the player controller to both inputs in the Target search for the character and connect it only to enable because you want the character to be able to move again also search for a set actor relative location and leave the values as they are set actor relative rotation as well then you'll need to detach the item set everything to to keep World in addition drag the mesh and reactivate simulate physics and collision search for set Collision enabled and set it to query and physics go back to your character in The inspect input so when the is not valid connect another interact with copy it connect self in the player character as well connect it to is not valid but the target here should be the current item go back to the parent and in the event graph you have the interact with event find the stop inspect input that you [Music] created when you click the stop inspect button it will trigger the stop inspect function you'll also want to search for the current item you can find it from the player character Set current item and connect it here I just realized that I've connected this here but it shouldn't be like this it shouldn't be connected here besides it should be connected to is not valid I believe everything is now complete and should work I'm going to make a small change to the cube making it smaller in the details you have the inspect distance which defaults to 100 and you can adjust it as needed based on the mesh hit play when I approach the mesh I press e to inspect I grab the object and I can't move if I press r i release it now the next step is to allow the object to be rotated go back to the parent in the event graph let's create a variable to track whether it's currently rotating this variable will determine if we can rotate the object find the left Mouse button when you click it you'll be able to rotate the object drag the variable set for both pressed and released when you press it it will be true and when you release it it will be false Now search for the mouse X you'll need Mouse X and mouse y to control rotation using the mouse drag is rotating add a branch if it's true and therefore rotation is allowed set the actor's rotation for the axis value you'll multiply it here set the rotation intensity a value of two or three should work well you can experiment with the value you prefer search for get actor rotation and combine rotators this will be the new rotation right click on the B and split it because we only need the Z rotation do the same for Mouse y copy this part just change one thing instead of connecting this to Z connect it to Y and connect this part to the axis value as well we compile Let's test it I'll pick up the object now if I hold down the mouse button I can rotate it perfect Let's test it with an object that isn't a cube go to the folder and rightclick on the parent create a child change the mesh to whatever you want I've set this mesh I'll set the default size we compile now in the scene I'll place a table to to put the actor on top of it position the actor you can adjust the distance here for now I'll leave it as is hit play I click to inspect I can rotate it perfectly the issue is that the rotation occurs at the bottom because the pivot isn't centered it's a bit awkward to rotate to fix it select the mesh in the scene and go into modeling mode here's the pivot and you can move it and place it in the center more or less where you want it to rotate click accept to save it if we try now it rotates from the pivot at the modified Center it protrudes slightly through the table but you can adapt the distance size etc for example I'll change it to 80 it's a bit closer and doesn't quite touch you can also add sounds when grabbing or releasing if you go to start inspect you can add a spawn sound attached at the beginning attached to the mesh you can make the sound a variable so that it can be different for each actor I'll change the name sound start do the same for stop inspect I'll copy it delete the variable and create a new new one sound [Music] stop both variables should be instance editable now in the details you have the sounds I've added a couple of sounds that come with unreal for testing Let's test it you can hear that it plays the sound correctly also keep in mind that you can set this value to negative in Mouse X and mouse y to rotate in the opposite direction it depends on your preference I hope you found this tutorial helpful and see you in the next video
Info
Channel: Nirnaeth GameDev
Views: 4,075
Rating: undefined out of 5
Keywords: unreal engine, unreal engine 4, unreal engine 5, ue5, ue4, gaming, gaming development, gamedev, blueprints, unreal engine tutorial, how to unreal engine, unreal engine beginners, create a videogame, epic games, unreal engine 5.1, unreal engine 5.2, unreal engine 5.3, item inspect, inspect item, inspect
Id: 0E8wtIcF12U
Channel Id: undefined
Length: 27min 24sec (1644 seconds)
Published: Thu Oct 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.