Inventory System UE5 Pt 6

Chris Didier
6 min readSep 10, 2022

--

Last time we were able to create the tooltip system and there was a drop item button that appeared, but we were not able to drop it. This time we will be able to.

First, we need to fix a bug that when we open our tooltip, but close our inventory menu our tooltip bar still remains. So let’s get that fixed first. Let’s open up the InventoryMenuScreen event graph. We are going to add the destruct event. This is called when this thing is removed from the parents or screen in this case. We also are going to our tooltip and remove it from the parent as well.

Now we can work on dropping our item. Let’s head over to the inventory component and instead of printing hello we will be dropping our carrot under the remove from inventory tab. For our function we need an input of our item name (name) and our quantity. We need to find how many we have available and we want to make sure we do not remove more than we have available.

We will make sure the value is less than or equal to our total. We also want to add so we can add our current amount and subtract from it. We also need to make sure that if the item has no value at all. If it is successful we will return success and if not it will fail.

Now let’s head over to the ItemToolTip and under drop item go to our on clicked event. Let’s get our item name. We are going to set our drop rate to 1. If successful it will update and refresh our UI. We will create a new event dispatcher and call it UpdatedSlot and then call it.

Now let’s head over to the InventoryMenuScreen show tool tip. We are going to get our tool tip and bind event to udpated slot. This will tell our UI to refresh itself.

Now let’s head over to play now and test this out.

Now we need to remove the tooltip as the item will no longer be there. So let’s head back over to InventoryMenuScreen [Event Graph]. Where we refresh we are going to get the tooltip and remove from parent. Then we are going to set the tooltip leave it blank and connect it to our get inventory component is valid. Make sure that the ToolTip is set to Instance Editable and Expose on Spawn.

Next is to make the object appear on the ground. We want to create a representation of our carrot asset. We are going to go into Quixel and download a carrot out of there. Once it has been added to our project we can head back over to the data table and add our 3D carrot mesh.

Now open up the ItemTest and head to the event graph. We are going to create a new variable ItemData(Data Table Row Handle). Make sure it is editable. Then split the get ItemData.

Before

From the item data data table we will get data table row, and on the out row we will break itemstruct. We will get our mesh component and set our static mesh and link it to our 3DMesh in the itemStruct.

Now go back over to the editor and select our ItemTest object that is in our scene. Go to the ItemData tab and select our ItemData table and the Row our object will be associcated with. So now if we hit play and load our scene we will have our carrot.

As we can see we are missing our material for our carrot so to get that added head back over to the ItemTest and off of the 3DMesh we will get the static material. Off of our Mesh we will set the material. Off of our static materials we will create a for each loop and we will break out of it when we have found the correct material.

If we head back and load into the game we will now have the correct material.

Next we need to increase the size of the carrot. We are going to get the size of our carrot from the data table. We first are going to go into the struct and add a new value called MeshScale (Float). Then go to the default values tab and change the value to be 1.0.

Now for our carrot we are going to want to set it to a MeshScale of 4. Back over in ItemTest we are going to multiply the mesh x the MeshScale. Off of our mesh component we are going to set the World Scale 3D. We will be connecting it before the for each loop. We then are going to multiply from our new scale and multiply by 1xfloat (connected to Mesh Scale).

We now have a much larger carrot when we play our scene.

We still need to interact with our carrot. So we will have to add a sphere collider to it with a radius of 50. Then change the Collision to custom so interactable is set to block.

We can now collect the carrot and it will appear in the inventory, but if we drop it, it does not come back into our world.

Change the name of itemtest to DroppedItem. We will also make sure our item data is editable and exposed on spawn as well.

Back over in ToolTip where we remove from inventory/call updated slot. We are going to create a branch before our updated slot and after it we will spawn our dropped actor. From the Item data we will make the datarowtablehandle and from our itemdatatable we will get the row name from item name.

The spawn transform is where the location of the owner will be so we will get the InventoryComponent, we get the owner of the inventory component, and we get the owner’s location which we attach to the spawn transform which is broken out.

We can now pickup the item and drop it back down.

Let’s head over into our dropped item and in the viewport take the mesh and make it the root. On the mesh we are going to enable physics. On the mesh we need to change collision and change the pawn to Overlap.

Open up our carrot 3Dmesh and add a simple collision to it. We will add a capsule collision to it.

We are getting some errors when we run that take us to InventoryMenuScreen [EventGraph] remove from parent. Convert the tool tip to a Validated Get and the other tool tip in the refresh event path as well.

--

--