Unreal Engine Pickup And Drop Items Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in today's video we're going to be making this pickup and drop system where you can pick up weapons like this and it attaches to your hands and you can also drop them as well like this you're also able to pick up multiple weapons as well so we can pick up these two and we can switch between them as well and obviously you can drop weapons too um there's also a stackable element to this so you can pick up weapons if you pick up too many you can't pick up anymore until you drop another one and you can pick another one up like that yeah that's what we're making today and let's jump right into it so before we start I'm just going to go over some of the stuff that I have which is the FPS weapon bundle and also the pistol starter pack this one isn't free um also animation stter pack but this one is free okay so the first thing we're going to do is we are going to um create the pickup system pretty much first so in order to do that I'm going to go into the tutorial uh file you can put this wherever you want really and then in the we're going to make a blueprint class then from blueprint class we're going to make an actor then we're going to call this master underscore item then we're going to right click and create a blueprint structure we're going to call this sore items the first thing I'm going to do is I'm going to go into the sore items going to open up like this then we're going to create a couple variables so I'm going to create one called name and this will just be of name I'm going to create one called class oh class like that and then going to create one of item then there'll be one eore state and there'll also be a socket name like that so for the class this will be um Class M Master item class reference the item we'll make it a skeletal mesh like that object reference refence the eore state we haven't done that just yet so we can leave that as it is for now and then socket name we'll leave it name so back in the content browser we are going to create a blueprint enumeration we're to call this eore state and this will just pretty much be all your States so for me I have three one is unarmed one is rifle and the other is SMG when I'm holding the SMG as these will be two different states as it have different animation States so then we're going to go back into the structure and where it says eore State we're just going to make this eore state like that next we're going to set up the master item go in the master item we'll open that up and then what we can do is add a variable call this sore items and this will just be of sore items like that okay so then the next thing is we're going to add add an interact Collision sorry not interact Collision just a box Collision which we're going to call interact Collision we call this interact Collision this will pretty much be what your player is interacting with to pretty much collide with it then we're going to add a new um component and we're going to call this we're going to get a static mesh which will be called smore item okay great okay so next thing we're going to do is we're going to add like a placehold asset for now we just going to add an AR SM AR for like that and we're just going to position it to how we want to position it so we can do this something like this looks good on the floor then what we're going to do is we're going to go to simulate physics we're going to tick that then go to your Collision uh make sure it's a physics actor and then and when you click custom you should just be able to go Pawn then overlap like that okay cool and actually something I've just thought of is instead of a box Collision we can actually just use a spere collision instead as it'll be a lot better it'll be a lot more it'll be a lot better for what we're trying to do not a severe sorry it's a fair Collision this would just be a lot better and then we can make it as big as we need it to be so lock that and just scale it up we'll disconnect the SM item from it we don't want that to be parented then just scale it up until your gun fits in there s something like that let's see how it looks like in the level drag it in and I think maybe maybe a bit bigger bigger of a collision scale up more just like that that little bit bigger about three yeah that's perfect for me okay great next we're going to go to the event graph and then we're going to on the seere Collision we're going to add add event and then go to on component begin overlap we can just delete these three okay so then we're going to promote this other act to a variable to a variable then we're going to check if this other character is equal to the player character then we're going to get we're going to connect this to a branch just to check if it's equal to it then if it is equal to it we're going to grab the player character like this just grab the player character then not sorry not the player character I don't know what I was thinking there but out of the TR just do enable input then grab the player controller not the player character player controller like that to play a controller right then you're going to do a very similar thing for on component end overlap so we can just copy and paste this part of the code this part here just like this other actor connected to the equals and from player controller you can just get disable input then put it into player controller at the true just like that great okay so the next thing we'll do is we will go to content and we'll just add a new blueprint interface this will be called BPI uncore inventory so BPI uncore inventory just like that then we'll open it up and we'll just call this add to inventory this will be an event to add it to the inventory then we're going to add an input of s underscore items which will be the variable sore items and it'll be an output of success which will be a Boolean like that now what we can do with this interface is go and find your player character mes here then you can just implement the interface into your player character so class settings implemented interfaces vpor inventory and that's all you got to do for now in the third person character next we're going to create the inputs so for the inputs we're going to go to uh third person input actions we're actually going to need quite a few for this so we're going to create um input input action IIA underscore um we'll call this interact and you can just keep this as default um stop the default values in here and we're going to duplicate this this one will be called IIA uncore slot one slot two 3 four and five this will just be how many slots you have in your inventory system then we'll duplicate one more time and call iore Drop Like This then we can go into the IMC context now we need to like Define all of these so add a couple mappings you're going to need a few then IA drop I'm going to make this my q key then for IIA interact I'm going to make this my e key or slot one going make this my one key slot two be 2 key then just keep going through all the slots until you set up all your keys so lot four 4 key and finally slot five be the five key okay so now what we're going to do is back in the master item we can just grab the IIA interact like this then off of start method we're going to do add to inventory like this and then s items will go in here and the target will be other actor like that then off of a branch if it's successful we will destroy actor like that that's all we got to do for the master item now you can close that the next thing we're going to do is we're actually going to create a proper item now you can delete the master item from here and then inside of my tutorial I'm going to right click Master item and just create child blueprint and you just call this item underscore I'm going to call this rifle be my rifle I'm just going to keep the static Mees stuff as the same cuz it's still the rifle but under item then sore items here we're going to change the name to Rifle the class to item rifle then the item to be the ar4 which have one I'm not too sure but I'm just going to put as this one then the state will be rifle and the socket name we haven't done that yet but just make it rifle like that okay so now we've done that what we can do is head back into the third person character and on under interfaces you can add to inventory now you can add this interface here and we're going to need quite a lot of room here this is quite a big function so just bear with and I'll explain it all afterwards so we're going to create a new variable called count we going to make this an integer and we're just going to set it here to zero next we're going to do a four each Loop and before we do that actually we need to create an array which will be called inventory so this will be an array of sore items and to make an array just come here and click array so then just add as many hot bar slots as you want so we've already decided that we want five so 1 2 3 4 five these all just keep them empty like that so next in the inventory what we can do is we can do four each Loop like this and make sure it's one with a breake so four each with breake then just plug this in the execute pin like that next we're going to break the array element like this just break it then we're going to check if the clock class is equal to nothing and if that's true if it's true then we're going to set array element so set array element and the target array will be the inventory the index will be the array index here and the item will be S items like that okay then we're just going to put this inside of the breake I think yeah so break that this add some reroute reroute uh pins here just to reroute everything like that okay then out of the completed what we could do is do a branch and we're going to grab the count then we're going to see if the count is equal to however many what your max slots is so my Max slots is five then out of the true we're going to grab this return node at the true will be not successful and just duplicate it and out the false it'll be successful and also one thing that I did forget to do is out of this false you're going to get a reference to the count and then you're just going to plus plus which is increment you're just going to increment the in like that okay so we we will come back to this and expand on it uh but right now we don't need to so then we're going to create a new function this function would be called get inventory item and we are going to create an input which will just be uh we'll this index and it'll be an integer like that and then we're going to make a for each Loop so you just hold F and click for each Loop and the gray will be the [Music] inventory and then we'll create a branch here and um pretty much the branch will be if the array index is equal to the index here then we're going to carry on so then what we're going to do is we're going to grab the array element and we're going to break it you need to expand it down like this now what we're going to do is actually create a new item so not an item in a ort add a new component which will be a uh skeletal mesh attach it to the mesh like this zero out the transforms and we can make it call we can just call it item like this no need to anything else to it we're going to do all the rest of it in blueprints okay so what we can do is grab the item and just set the mesh set skeletal mesh asset to be whatever this item is then we're going to create we're going to promote this e state to a variable just keep it as e State then plug it in like that then we're also going to do attach component to component component to component item like that so item will be in the Target the parent will be the mesh the socket name will be this socket name here and you just keep the rest relative like that then we'll just add a return node add return node and we're going to plug in this array element here we're just going to call this current item and then we'll also plug the array index in we'll call this urrent index just like that and I made a mistake this isn't actually going to come out of the or for each Loop it will be the index plus it straight through there as well all right so what this does is it will Loop through each item in the inventory um check if that item is equal to this index and then we're going to just set up all the items and stuff so it looks like the items is in your player's hand uh you'll set the state so the players in the right State you'll then attach the item to the correct bone so the items in place correctly then it'll just return the current item and the current index okay so now what we can do is just find some space then we can just grab IIA slot one like this and then grab IA slot two and then just keep going down until you get get to slot five for me slot three slot four and finally slot five now these will be pretty similar so you can grab you get inventory and on not triggered make sure it's on started get inventory item like that and then just do this and you're going to put that on each of the started do for all of [Music] them there slot four and Slot [Music] five so once you do this you'll then be able to just get the current ice and promote this to a variable then get the current index and also promote this to a variable then just drag out these like this so now you have a reference to the current item current index so now the current item we're not actually going to use in this tutorial if you wanted to expand on this further then the current item you will need for like say displaying the inventory in a widget and stuff so if you'd like a tutorial on that just let me know and I'll obviously make one we're nearly done for the picking up an item portion of the video which is good so this is pretty much the whole pickup system uh now we're just going to make the drop system so but before I do that before I forget make sure the index is zero and then the second one will be one then two three and so on like that we start from zero because all arrays start from zero and we ended four because that's the last slot also before I forget we'll go back to the add to inventory and what we're going to do here is add a little bit more code because we can do this now so get inventory item and you're just going to plug the current index into here sorry not the current index we're going to plug this array index here and the rest is fine never mind I was wrong you're going to plug the current index into it I was correct initially actually and then you're just going to plug the current item here like this and then the current index in here as well and then you can just plug this back in now the add to inventory function is now done and so we're going to start with the drop item now so in functions we can just a new create a new function with that drop item then in here what we can do is add an input or this item then sore items with type and then what we're going to do is we're going to break this and get the class and just spawn actor [Music] now for the transform we're actually going to create add a new scene component like this connect it to the mesh and then actually we yeah we'll connect to the mesh it will work and then we'll just drag it a little bit in front of the player like that that's all we're going to do go back into the drop item get reference to the scene and we'll rename it to like Drop pause or drop position and then we will get transform get transform and it will actually be the world transform get World transform and just spawn in like [Music] that okay next thing we're going to do is we're going to set array element again set array element like this and then the target array will be inventory and the index will be current index and then that's what we got to do for that and then what we can do is we can set we can get a reference to the is first and then we can set scall mesh asset like that delect to none just leave it as default then get current item make it nothing and get current index and also make that nothing or not current index it will be the variable which we accidentally made local I think um let me find it real quick I made a bad mistake or did we no we didn't I I'm just blind so we can set the E state to now be unarmed like this [Music] now that's the whole drop function let implement it all we're going to do is grab the IIA drop action event and then just link this up to drop item out started drop item and the item will [Music] be and the item will be current item so like that I'm we going to drop the current item actually we do use this I've only just realized so now that's the whole pickup and drop system done um what we're going to do now is we're just going to make it so we can equip the weapons and you enter the right State while it's doing that so something you should make sure you do that which I forgot to do actually is this other reor should be connected here I completely forgot to but if You' like you can test it out and so far this is what we have so you're just able to equip your weapon like this and it does Equip to your feet which is rather strange right now but it's it's a work in progress okay and you can also um switch to your unarm slots if you would like yeah that's what we've done so far so what we're going to do now is we're going to prepare our animations so what we're going to do is go to animation then go to blend space and I'm going to find the skeleton which is SK mannequin then we're going to call this bsor rifle this will be for the rifle animations so what we can do is use grid pick I think I'm not too sure what that does we'll take it for now and let's just see what it does I guess so if you want to add directional animation to this you are more than welcome to so I'm going to call the horizontal axis directional not directional just Direction um and then we're going to set it to- 180 and then 180 keep this as four and then snap grid um so yeah this is set up for direction Direction animations however I'm not going to add Direction animations if that makes sense um but it's something you can do if you'd like to then the next AIS we're going to call speed this will be zero and this will be 600 then snap the grid okay so what we can do is just rifle idle rifle hip this our first animation that we use the next one will be rifle jog look forward and the final one is rifle Sprint which is Sprint forward rifle just like that okay great and then we're done with that actually for now and then what we can do is go to animation uh blend space again find dra player skeleton and then we're going to create one for the SMG [Music] so do the same thing again so Direction Min - 180 180 tap to grid speed Z 600 s to grid and for this I'll just use the pistol idle pistol I think it's not called that I remember what it's called let's see if I can find it [Music] actually here is stand relax and then I've also got a dog for this one as well like that so I'm just going to put two animations for this one cuz I don't actually have a Sprint it's fine then we'll create another blend space this is going to be the final Blend space we're going to make but preferably to make your game look realistic you want to have blend spaces for each different weapon so everything fits in the player's hand correctly this would be B bsor unarmed this will just be your basic locom motion so this will be mm idle this I forgot to set up the Axis so direction- 180 180 up to grid speed 0 to 600 after grid then just idle um run forward at the top and walk forward in the middle like that okay and then what we can do is go into our characters mannequin animations AB Manny this is the one I'm going to be using you can use Quinn if you want to completely up to you it'll be the same thing either way okay so what we're going to do from here is in the locom motion we can just um delete this one and keep the idle however instead of playing the idol animation we are going to play the unarmed and then just plug the speed in like that plug the speed in and then out of the idle we're going to add a new state for this rifle this will just be the rifle like this and then ground speed PL speed and then from the idle again add new state this will be SMG and then what we can do from here is in here at the SMG and space like that ground speed all right so what we're actually then going to do is create the transition lines between all of these this there we go okay so now we're going to go to the event graph and we're just going to um delete that cast to character and we're just going to cast to third person character instead so third person character plug everything back in but you're going to change this variable to be third person character as well third person character like that and change rable type you got wait and then plug everything back in file and save now what we should do is add a new PIN from references character grab the uh I think it's called eore State we call it e State yeah get State and you to promote the variable like this plug it into the sequence that's all you got to do for that next head back into The Locomotion here and then to go from idle to Rifle this is going to be quite repetitive but just you have to bear with me on this one so eate you got to check if it's equal to enum this enom will be uh rifle then you can just copy copy this may sure you copy it otherwise it'll get very repetitive very quickly then from rifle to Idol it will be unarmed then from idle to SMG will then be SMG and then from SMG to Idol be unarmed from SMG to Rifle will'll be [Music] rifle and from rifled SMG [Music] SMG yeah I should be all of them I think I'm not too sure why we still got ah we didn't do the SMG to rifle so like that okay so then just head back to the anim graph and we're just going to delete this control right here just remove that completely so now you'll see when you pick up the oops didn't mean to open like that but now you can see when you pick up the rifle your character is in a different state now and when you go to a different slot it goes back to the normal unarm State like this okay so now we going to think about putting this gun in his hand now it looks absolutely ridiculous um with it just by his feet so let's go work on that now to do this what I'm going to do is go to the third person character and I'm going to actually first of all change the mesh to Manny and I'm also going to change um the anom class to ABP Manny like that and then we can just double click this [Music] mesh find where it says right arm so go [Music] down I don't know where it would be so I'm just going to search for it handcore r andore r and then you can just add a socket right click add socket then F2 to rename and I'm going to call this um rifle and I'm also going to add another socket which I'm going to call SMG SG like that save that and then we're just going to go back and find the hand R it'll be easier to find cuz you'll just see this these two icons here so first we'll do the rifle so right click add preview asset ar4 like this um preview animation make sure we're previewing in the BS rifle and then just rotate it so it fits into the hand rotate and move it freely so then it fits inside of your character's hand perfectly so this and take a while depending on how precise you want to be with it but you know I just recommend take your time but that looks pretty good for me then what you're going to do is just hold hold your mouse button over the sk4 and just click delete delete then just add preview asset for the SMG um use this one I believe then change the preview animation to BS SMG and then rotate this one to fit inside of SMG as [Music] well rotate and move it it fits in well I'll be honest I wouldn't recommend using the animations for the SMG it doesn't really look good like at all since this meant for a pistol however um this I'm just pretty much showing you how you can use use it to do multiple weapons so it's just for the tutorial then you can just delete this preview asset as well so if you go back into the item rifle um make sure where it says so socket name just make sure this is Bel correctly the same as you've pretty much named your socket that we just created so we made one called rifle so we called that rifle then when you play it should just go straight into the hand like this and yeah drop it you can pick it up um yeah this is pretty much all all that um we need to do so if you want to make new weapons you can um fairly straightforward I'll do it with with you right now so we can create another weapon so tutorial right click Master item create child item undor SMG just so I can show you guys how we go about it so first thing you do is you just change this mesh to your FG um 11 mesh we can just use we'll just use this one unless is a better unless it's a better mesh somewhere maybe I'm not too sure all right yeah why seem should put it flat on the ground like that where it says item self you can go to S items you can name it we'll name SMG the name doesn't matter but it will when you want you start getting into UI of this and as I've said already if you want a tutorial on UI um just comment down below and I'll be sure to do it so then you make the class item SMG this will pretty much be the item you dropped from it you say we made an item rifle when we drop the weapon would actually drop the rifle instead of the SMG so then we'll make the item this will just be the item that appears inside of your hand so we'll make it the smg1 X the state will just be what state you want to be in when for the animations so we're going to make SMG then for the socket name SMG just a socket we created for the SMG then you just drag into your world and that's it you can then play pick up the AR and then also up the SMG Swit SMG and there we go it's working perfectly so now that's everything we need to do for the tutorial thank you guys so much for watching and comment down below if you want to see anything else any suggestions comment down below subscribe and yeah that's all I got to say thank you very much and [Music] goodbye
Info
Channel: MrKnowBody
Views: 8,785
Rating: undefined out of 5
Keywords: unreal engine 5, unreal engine, unreal engine 5 tutorial, tutorial, game dev, unreal engine tutorial, game development, ue5, MrKnowBody, The Ultimate Guide to Pickup and Drop System in UE5
Id: hbWaFSnUq2w
Channel Id: undefined
Length: 36min 20sec (2180 seconds)
Published: Sun Jan 21 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.