Unreal Engine 5.4 Create your own game tutorial / 8.2 Unequip Equipment Slots and Remove Item

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so to continue with our equipment slots now we need a function that will remove item from the inventory when we equip it and also a function that will remove equipment from the equipment slots so first thing we're going to do is in your player blueprint in the functions we need to create a new one this will be our remove item this needs a input because we need know which item we're going to remove so we will pass inventory reference inventory index inventory Index this will be integer compile and save and now we can get the inventory get a copy we get this item on this index and now from there we break it open and we need to check if the stack is at one um so if it equals we can also do less than equals one but we most likely won't be running this function ever if there is no item to remove so but just to be safe do less than equals 1 and now branch if it is then we remove the item so we get the inventory and we remove not the item here we remove the index um and the index we need to remove is this one here instead of dragging it all the way here you can just get it so get inventory index I wrote inventory so just change it inventory index there we go now get it again connect it here and now if the Stag is more than one we need to change that item change it stack so get a inventory set array element connect this here and from set array element we uh make item info here from the item here from the G you can break it open and we just need to remove one stack so connect everything apart from the stock and for stock we just do from the item we got in in the inventory we substract one so minus substract and we substract one I actually forgot to connect the index here so this inventory index from the function needs to go here as well so just copy this and paste it into index then compile and save now we connect it in in inventory icon in graph here where we after we attach the equipment we can so get this all the way maybe get a new player reference copy it again and here copy it one more time and get remove item not the array remove item function call function and connected in the end and now if you compile and save and went into your game now when we equip the item it won't show us straight away close the inventory open it and it didn't actually remove it so uh we haven't connected the inventory index which is the inventory index variable from the Icon we're clicking on so compile and save now try to play it equip the offun close the inventory open it and it's not here anymore uh now obviously we need a way to refresh the inventory we can be closing it and opening it all the time so to do that go to blueprint and widgets and open inventory widget in here we need to go to graph we basically here we need to need a way to refresh this inventory grid so go to graph and here where we're building the inventory we can just create a custom event at custom event and we'll call this refresh inventory we could call the build inventory but refresh inventory is just so we know what we're actually doing we already refreshing equipment slots so it will be the same but here one thing um if you don't reset this in row in on column it will be just adding it on until you have about 100 columns after few refreshes so just set this in row here and in column back to one which is default value is one one and we also need to clear children we get the inventory grid variable and every time we refresh it we want to clear the children because when you do it a few times and don't clear the children they will stay in a memory and eventually your game will slow down so this is the way around it to fix it and now refresh inventory you just can connect here compile and save and now in the inventory icon we can in the end when we refreshing equipment slots we can get player reference and then inventory reference and we can refresh inventory compile and save and now if you were to play the game it will actually do it straight away now we need a way to unequip it and obviously if you're equipping items uh these ones need to go back to inventory so so to do that we're going to create new function in player blueprint this one will be remove attached item this one also need an input so uh add it here this will be the slot index and we need to get our attached equipment info get it and we need to find we looking for this slot index we can break this one open so break item info and now we need to check if the class is valid so is valid class because if we click on an empty equipment slot we don't want to be removing anything so connect it here and if it is valid class uh then we can just pick up the currently equipped item so we call pick up item function uh the item we're picking up is this one just make it bit nicer so double click on the wire and after we pick up the item we also need to remove it so we get the attached equipment info and remove and the index we're removing is the one we connected here the slot index so just get slot index get slot index perfect now compile and Save now back in the inventory icon now first thing we need to do it before we add a new item and everything because if we add a new item in the slot then we can't pick the old one anymore so move this down and here we will get the player reference one more time we get that new function attached uh remove attached item and here you can hold control go over this pin and drag all of this to here the item we're removing is this equipment slot index so we connect that Here and Now if we were to play the game Let's test it out and we equipped 200 and then we equi this one it picks it back to the inventory of hun is off hun but the main weapon you can swap this the one thing now you can see is uh obviously if we equip two H we don't want to have anything else equipped so we want to unequip the off hand as well and same thing probably if we equip the off hand and there was a twoand equipped we want to unequip it so to do that here from the 200 weapon we we copy this remove attached item you need another player reference copy this here uh and Slot index instead of jugging it from here we will be removing zero we will be removing slot index zero because that's where the main weapon is sorry uh we'll be removing one because that's where off hand is so if we equip 200 and there is a off hand we'll remove it and now so that should be working fine let's quickly test it out so if we got off hand equipped and we equip 200 and unequip it but it doesn't do it all the way around so if you equip offand it doesn't unequip the two-handed one so for that we need to create one more F function uh in a play blueprint we going to create is 2 200 equipped is 200 equipped and this one will just get the attached equipment info we will find we will find the equipped item on slot zero we'll break this open so it's a main hand slot we'll break this open we will not check if the item class but we will check if the item type equals equals inum and if it equals 200 then we return return add return not and we also need to return the true or false so you can drag from here and connect it and now connect it back to here right that's all we need to do in this function is basically just checks if the 200 is equipped compile and save it we can also make this function pure what I will do it will remove the this type of pins as well you will see in a second so in the inventory inventory icon here drag this all back again I need a little bit more space uh here when we equipping off hand so when we equipping off hand here we need to check uh we need to drag on from player reference and check is 200 200 equipped and this is what pure function looks like look looks like now we do branch of hand and now we can actually connect the shield because Shield is the off hand slot as well we can connect offand to this one and return value from this function here so if the 200 is equipped true we also need to [Music] remove it's getting a bit Messier again but we also need to on true we need to remove slot zero if it's only single hand like main hand equipped we don't need to remove that so on false we just remove the one we got equipped in the same slot so not this one uh here you need to connect the player reference as well all right just to make it a little bit so you can drag this down make a little bit more spaces between them and now this one goes here this one goes over and then here still put this a little bit more down there we go and I'll just this false right perfect luckily we don't have to do anything like this in the armor slots this is just for weapons and it's just the way I'm doing it so we can actually have a 200 and off hands and stuff like that uh delete this one can have a look and now if we compile and save this that should work fine so offand now 200 it's equipped now off hand again 200 is unequipped singleand single hand 200 we can just switch between these three also now we need a way to unequip it from the slots so uh in your equipment slots so blueprint widgets equipment slots uh on the button go all the way down and now we need to create onclick event and we just need to do uh from player reference we remove attached item and the item we removing is equipment slot index the one we clicking on uh we also need to refresh the equipment slots so from player reference get inventory reference and refresh equipment slots and refresh inventory because uh we will be picking that item up so refresh inventory as well there we go compile and save and now if you go here and unequip this unequip this now it should be all working perfectly fine right and while we still doing this we can also set up the slots for armor even though we don't have any items just go to enumeration for item types and add the the ones that we the five of them that we created for armor which is head chest gloves uh hands legs and feet save this and now uh in the inventory icon you're going going to have all of these which is basically need to have this equipment slot set up so we copy this uh five more times and in equipment slots in design oh no it was in equipment preview preview any your widgets so equipment preview and here you got head is 2 three 4 five and six so it's quite easy so go back to your inventory icon and do 2 3 4 5 and six and connect the correct one into it so this is what I mention is you don't want to create way too many slots because just getting a little bit messy and it goes back to here to remove attached item uh if you like you can create the redirect and you can connect these ones to Here There we go compile and save and now all of the slots will be working if you were to create your own armor now it will just equip it to the correct slot and that's it for this video so obviously later on we'll also be equipping this to the player but now we're going to focus on finishing the inventory properly you know maybe drop item and all the other stuff we need here in the interface so all right I'll see you in the next video [Music]
Info
Channel: Click.o
Views: 146
Rating: undefined out of 5
Keywords:
Id: Q0cofWNQTyI
Channel Id: undefined
Length: 20min 58sec (1258 seconds)
Published: Thu Jul 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.