Forum rules - please read before posting.

Backpack Inventory

i have 2 item in scene for example shotgun and key so when i pickup shotgun i want to store it on inventory 1 (called it "backpack") then it should be dragged or moved to inventory 2 (called it "in game inventory") to be able to equip or used ( i have my own custom action for equip it throw action list) , and same as this for key or any other items.in short term i want to have 2 inventory one for containing , rearranging and crafting ("backpack") and another for usable purposes only ("in game inventory"). i think about categories but since i cant find anyway for switch item category on runtime this should not work and other way that i try was using unity UI prefab and split it to 2 part but this one was not work like i was thinking to , so any other way or workaround would be appreciated.

Comments

  • edited December 2018

    While the inventory system isn't designed with this behaviour in mind, you can switch an item's category at runtime - right-click on an Item's Category field in the Inventory Manager to get an API reference to it. An item with ID=3, for example, can be modified with:

    AC.KickStarter.runtimeInventory.GetItem (3).binID

    You can replace the GetItem (id) method with e.g. SelectedItem / LastSelected to make it dynamic - see the Manual's "Inventory scripting" chapter.

    To run this code when e.g. clicking on "in game inventory" when you have an item from "backpack" selected, you'll likely want to rely on the OnMenuElementClick event. Something like this:

    http://pasteall.org/1406720/csharp

    You'd have to set each InventoryBox element's type to "Custom Script" for full control over it. Optionally, you can define a Button named "TransferArea" that spans the inventory to "catch" clicks on the portion of the inventory that isn't yet filled with items - so that you can move onto empty spaces.

  • edited December 2018

    thank you chris .
    i read "Inventory scripting" and i have good concept of it now , but since i am still so noob at coding a complete sample for this one would be so nice. then i have 2 questions:

    1. this code should be attach to button slot on "backpack" and "in game inventory" UI prefab and used it on "On Click()" section on inspector? but how ?

    2. OnMenuElementClick event Script should be on the empty object in the scene as a listener only for transfer between 2 inventorys?

  • chris !!!
    i have another easy way on my mind if it would be possible.
    create 2 AC inventory menu with 2 category named "backpack" and "in game inventory" , make all items as "backpack" item category from fist place then when we click on any item on "backpack" a custom action run throw action list that remove item from "backpack" and then add it to "in game inventory" (based on "Inventory scripting" reference). with this method you have 2 separate full functionally inventory and it would be so cool if it be possible on this way!!?

  • Well, that's similar to what I've already provided - simpler, actually. Both rely on the OnMenuElementClick event to control what occurs - but my last script allowed for both ways around.

    Merely clicking on an item in the backpack to auto-transfer it to the in-game inventory is a lot easier - there's no need for a "transfer area" or anything like that.

    Try this:
    http://pasteall.org/1413524/csharp

    As with the last script, you don't need to attach it to each button or configure OnClick - just one copy of it in the scene, with its Inspector configured, is enough. This hooks into AC's event system, not Unity's, so you shouldn't have to play around with any of the Canvas Buttons etc.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.