Inventory System – Part VII – Dropping Items In World – Part 1

Brief Overview

In this tutorial, we’re going to use Unity + Bolt Visual Scripting to drop individual items back into our world. Let’s Begin!

Getting Started

For this tutorial, we’re going to add the capability to drop single items into our world with a right click function on our mouse. To be able to accomplish this, we’re going to need to set up a few new Flow Macro Super Units as well as make some changes in our Object Manager Game Object.

The ReturnItem Flow Macro

In under the Macros –> 6 – Object Manager folder, add a new Flow Macro Super Unit and call it “ReturnItem“. Then add the following units to the graph:

The ReturnItem Flow Macro Super Unit

There’s a lot going on with this graph, so let me attempt to explain. When the right click Flow comes into the graph, it checks to see if the Pointer is Over Game Object which is our Inventory UI Panel Game Object. If it isn’t, it checks to see if the ObjectPicked is True (in other words, an object is actually picked up and in your hand). If it is, it Instantiates the game objected in the PickedSlotList by getting the Count and Subtracting 1 from it (we subtract so that if there’s only one item, we can get the last item on the list) Also, make sure you use the Scaler subtract instead of the Generic subtract because we’re using an integer here, not a float. We set the location to be dropped where our Mouse Pointer is by using the Screen To World Point unit, only grabbing the X and Y while setting the Z to 0 (we do this because the Camera is on a -10 on the Z and we need to set it to 0). Because we set up the Subtract unit in the Get List Item function, we are actually able to simply Remove that List Item (which is a neat little work around). Finally, we Count the items in the List to see if it Equals 0. We then run that Branch into a True and False Output.

Changes to Our Object Manager

Now that we’ve got that completed, we actually have one more thing to do before we’re done with single units.

Under our Object Manager, we need to place the ReturnUnit Flow Macro Super Unit here:

The ObjectManager’s Flow Macro

Once we place the ReturnItem Flow Macro Super Unit, we need to run an On Mouse Input Left Button Down into the Left Click and an On Mouse Input Right Button Down into the Right Click. When the is Equal to 0 branch returns True, we set the ObjectPicked variable on the ObjectManager Game Objecte to False and run into This Branch. Be sure to run the False return here.

If you test your game now, you should find that you’re able to drop single items in the world. Next we’re going to cover the ability to drop single items in empty slots in the Inventory UI. This actually needs to be taken care of in two places. The reason why is because if we have an item in our hand, we will either click on an empty slot (which requires action in the Item Slot Game Object’s Flow Macro) or on another item (which requires action in the Item Game Object’s Flow Macro).

We’ll start in the Item Slot Game Object’s Flow Macro.

The DropSingle Flow Macro

Under the Macros –> 2 – Item Slot folder, create a new Flow Macro and call it “DropSingle“. Then add the following units to the Flow Macro:

The DropSingle Flow Macro Super Unit

Let’s look at each of these things individually.

Section 1 of DropSingle Flow Macro Super Unit

The first thing we check with this Flow Macro is if an item is in our hand with the ObjectPicked Object Variable on the ObjectManager Game Object. If something is in our hand, we Count the Items in the PickedSlotList on the ObjectManager Game Object, and determine if there are less than 2 (meaning only 1) items on in the PickedSlotList. If there are less than 2 items, we Trigger the ItemAdd Custom Event on this Item Slot and Clear the List. If it’s more than 1 items, we Trigger the ItemAdd Custom Event on this Item Slot and Remove one Item.

Section 2 of DropSingle Flow Macro Super Unit

Here we simply set the ObjectPicked Object Variable on the Object Manager Game Object to false, and Trigger the OMUpdate Custom Event to update the picture and/or number.

We will then drop this Super Unit on the Item Slot Game Object’s Flow Macro, running the Right Click into the Input of Drop Single.

If we couldn’t click on the Item Game Object, this would actually be sufficient to cover dropping single items. But since we can click on the Item Game Object, we need to design a work around.

The AddToStack Flow Macro

For our Item Game Object, we’re going to create a new Flow Macro Super Unit under the Macros –> 3 – Inventory Item folder called “AddToStack“. This is what this Macro needs to look like:

The AddtoStack Flow Macro Super Unit
Section 1 of AddtoStack Flow Macro Super Unit

Here we check to see if an item is in our hand with the ObjectPicked Object Variable on the Object Manager Game Object. Next we see if the item is Capped on the Parent Game Object (the Item Slot).

Section 2 of AddtoStack Flow Macro Super Unit

If the item is Capped, we check to see if the Item in the Slot is the same as the Item in our hand. If it’s not the same, it will trigger the ItemSwap CustomEvent. If it’s not Capped, we also check to see if the Item in the Slot is the same as the Item in our hand. If it is the same, we trigger the Custom Event DropSingle on our ItemSlot. If it isn’t the same, we once again trigger the Item Swap. This is necessary to ensure that we don’t add more items in our stack than the Capped limit should allow.

We will drop the AddtoStack Flow Macro Super Unit on the Item Game Object’s Flow Macro underneath RelocateItem and run the Right Pointer Click Flow into the Input.

ItemSwap Custom Event

Remember how we Triggered the ItemSwap Custom Event? Well we need to place that in the correct location in our code. It goes right here under the RelocateItem Flow Macro Super Unit:

The RelocateItem Flow Macro Super Unit

Quick Change to Item Slot

We actually need to double back to our Item Slot Game Object now and add the following Custom Event:

The Item Slot Game Object’s Flow Macro

The DropSingle Custom Event should now allow us to drop a single item in the Item Slot if it’s empty or if it’s the same item until it’s capped. If it’s capped, it will stop doing anything. If it’s not the same item, it should Swap the items!

Conclusion

We should now see, that when we test this, we can Right Click to drop single items back into our world and our Inventory UI.

What if we don’t want to drop single items in our world, but a whole stack and be able to pick up whole stacks and add them back into our system? Well, that’s what we will cover in the next tutorial.

If you found this tutorial useful, maybe you’d consider supporting me on Patreon! You can do this by visiting my Patreon Page here! According to your level of support, you could have access to my Private Discord Server, take part in Online Polls for Future Tutorial Content, get a Shout Out in one of my videos, gain Early Access to Future Tutorials, and even Download My Completed Project Files!

In the next tutorial, we’re going to address dropping whole stacks of items and address what we need to do to add those stacked items back into our system.

Keep it Real,

Megahertzs

PS: I’d like to thank the following people for helping me play test this system to find most of the bugs!

  • MrVastayan
  • JSM
  • AliveDrive
  • Jorotyn

Also I’d like to thank these contributors for being there to help answer my questions and even provide solutions for my problems:

  • Zer0
  • JasonJonesLASM

Couldn’t have done it without these guys!

Leave a comment

Design a site like this with WordPress.com
Get started