+2
Answered

Inventory Window Click and Drag Substitute?

Gem 5 months ago in Inventory updated by Marti (Lead Developer) 5 months ago 3

Finally progressing enough to implement this Inventory module into my game!

Everything in this Inventory System works so well, really loving the RPG-Advanced inventory UI specifically!

But the problem is I'm making a platformer game that's controller-oriented.

Apparently I had assumed that because the Game Creator Character controller supported game pads the Inventory system would too but this was sadly not the case.

When I realized this Inventory didn't support it I was able to watch a few tutorials on how to enable a gamepad to work with unity UI and canvases, and it actually works pretty well once I add an "Event System" & "Standalone Input module" with a 'select first' component into it and set the buttons to darken so you can tell when one is selected! I believe I'll also have similar luck when I do the same for the Merchant and Container windows.

The only problem that's stalling me is that I cannot drop items even with this method, as the only way to do that is click and drag one out of the item window. I guess I also miss out on combining too, but it's the same thing - it only works via clicking and dragging with a mouse.

I had an idea that maybe the easiest way to remedy this, would be that when you select & click on an item it could pop up a little window with options like:

> USE

> consume/Equip

> combine

> Drop

etc

• And if you use/drop something while standing within an object's collider it triggers the "item drop" trigger on it? This would make the 'click and drag' feature a nice shortcut rather than the only way to do it.

Maybe this extra options window would even be possible to make using the Module's built in Button

Actions component? Tinkering around now but not sure how to force the game to drop the item I've selected... Been several days now and so finally seeing if anyone has any ideas.

I feel like this inventory would be close to being gamepad-friendly if not for this one thing, is this possible?

Unity version:
2019
Game Creator version:
1.1.7
+1

I would also like to see an alternative to click-and-drag, even when using a mouse. For instance click to pick up, and then click again somewhere else to drop/combine/whatever. But I have not experimented much with the inventory system, so it could be there is a proper way to do this already.

I don't think there is built-in alternative unfortunately. However, I think I've managed to make a bit of progress!

So at first I tried to manually force the inventory to drop an item via the

Action: Inventory>Drop Item (key) while standing inside a collider that has the

Trigger: Inventory>On Drop Item trigger (key), but this for some reason does nothing? What is the purpose of the 'Drop Item' Action if it can't be detected by the 'On Drop Item' Trigger?? Maybe I should bug report that?

Either way, after that I tried a diff method.

I looked around in the triggers to see if there was a "On Use Item" similar to the "On Drop Item" or "On Equip Item" but it doesn't seem to exist, which was surprising, you'd think you'd want a trigger that can detect if you used a potion in it's vicinity or something?

But I thought maybe I could work around that, so I picked the Trigger:Inventory>On Equip

What I'll be doing below is to try simulating Using an Item by Equipping it.

-I made a duplicate of that wearable Hat item in the catalogue (came with the InventoryExamples)

-I renamed it "Item that can be Used" or whatever (The fact that it is a hat is not important, it just needs to be equippable)

-I removed the "On Equip > Attach from Head" and "On Unequip > Remove from Head" because I don't actually want the items I use to pop up on the player model.

-I made a game object with a Collider with the Trigger:Inventory>On Equip Item and set it to detect if the Player has equipped the Item: "Item that can be Used", and to play a simple message when that happens. (to show it detects it)

It works, but, I don't want to run around with an item always equipped -I only want the item to be used in that instant, then if it was the wrong place to use the item, the player can open the inventory and click the item again to see if it can be used in a new location etc.

-So I go to the item catalogue and select my item. Under the "On Equip" Tab (Next to Conditions Tab) I create an Action: Inventory>InventoryUI and set it to close. (I want the inventory to close when I "use" (i.e. equip) the item)

- Action: General>Wait and set it to 1 second

- Action: Inventory>Unequip Item and set it to unequip this item from the player. (or unequip everything from this slot, either way.)

Now, when you bring up the menu and "use" the item, it will equip it, close the inventory window, allowing it to trigger any gameobjects you have set to react to it, then unequip the item after 1 second (or however much time you want) -this way you never have to go back into the inventory and unequip an item that you 'used'. Doing this really simulates other games where you could just open inventory, select an item and use it, then the menu would close and if you used it in the right place something would happen.

The only thing is, this takes up the Headgear slot in the equipment menu. I don't really want whenever I use an item to unequip my headgear (because that's the slot it goes to right now). So it's probably best to create a new equipment category and equipment slot seperately for Usable items, so you don't lose your Headgear slot to them.

The only thing is, while I technically can make this work, I wish I didn't have to mess with this system in this way to accomplish it. I wish the action of "Drop Item" actually triggered the "On Item Drop" trigger. Or even moreso I wish there was just a little options popup when you click on it to use the item like basic RPGmaker...

Oh well, either way it's possible.

Next up, I have to figure out how to accomplish combining 2 items with just keys/gamepad.

Will make a new post when I either succeed or fail.

Answered

The issue here is that each person has a different take on how an Inventory should work for their game and there's no simple one-fits-all solution. I guess the best is to use a custom skin if you want it tailored to your needs. 

Despite this, in order to make the Inventory navigatable using a gamepad should simply put the focus on the first element and let Unity UI handle jumping between focusable elements.