Hello,
i am curently developing a Inventory System for a game i am making. I want to share this thing for you, completely free. You can use it in any project you like without asking for permission (maybe a lil note in the credits would be nice but you dont have to).
The whole System (so far) is a Backend for a Graphical User Interface, wich means its just the Code not the fancy Graphics (Yet).
Blueprints & Co:
The zip file needs to be extracted to your Game/Content Folder. Inside the folder you’ll find (in the Contentbrowser) a rInventory Directory wich holds two more Folders (CoreBP, ItemBP), and the main Actor File (Inventory Actor).
The “CoreBP” Folder contains a “Item_Master” Actor and a custom Structure.
The “ItemBP” Folder contains a Sample Item Actor.
Functions:
Spawning the System / Setup (at Runtime)
Just rightclick in your SpawningBP and chose a “Spawn Actor” Node, then for Class chose the “Inventory_Actor”. The Actor by default is Hidden in Game so dragout a wire from the Transform parameter and use a “make transform”. The Size pin represents the actual Size of your Inventory in Stacks (How big a Stack is depends on the Setup of the Item, ill explain this later).
Useing the Inventory:
(Most of the Time you will use the Core Functions)
Add to Inventory: This is your Bread and Butter Function to Add items to your Inventory.
Target: Reference to the Inventory Actor
Class: The Item you want to add
Amount: How many Items you want to add
Result = False if Inventory is full wich means the amount you want to add cant be added because there simply isnt enugh space
Remove From Inventory: This will remove Items from the Inventory. (the first found in the inventory)
Target: Reference to the Inventory Actor
Class: The Item you want to remove
Amount: How much of the Items you want to remove
Result= False if there aint that much items as you want to remove
Remove From Stack: This will Remove a certain Amount of Items from a Stack (or completely remove it)
Target: Reference to the Inventory Actor
Index: The 0-based(First item is at Pos: 0) Index in the Item Array
Amount: How many you want to remove
Result = Same as above
Reorder Inventory: This functions combines all items/stacks wich can be combined.
Target: Reference to the Inventory Actor
Split Stack: Splits a certain Stack into two
Target: Reference to the Inventory Actor
Index: The 0-based(First item is at Pos: 0) Index in the Item Array
Split At: If you Split a Stack of 15 at 7 the first stack will have 7 Items and the second one will have 8. Must be > 0 and smaller < than the stacks maximum
Result: False if there is not enough space in the inventory to split
Combine Stacks: Combines/Merges two Stacks into one. Or fills the target stack to the maximum.
Item Max Stack: 15
StackA: 5 Items
StackB: 12 Items
= StackA = 15, StackB = 2
Item Max Stack: 15
StackA: 5 Items
StackB: 10 Items
= StackA = 15, StackB = gets removed from the Inventory
Target: Reference to the Inventory Actor
IndexA: The 0-based(First item is at Pos: 0) Index of the Target Stack in the Item Array
IndexB: The 0-based(First item is at Pos: 0) Index of the Source Stack in the Item Array
There are also some Helper functions wich can be called.
Get Item Data from Class: Get the data wich is stored in the Item Actors.
You can modify this one to retrieve other data you specified in the Item_Master actor. (Ill explain this later)
Target: Reference to the Inventory Actor
Class: The Item wich holds the Data you want
(See function nodes and Item_Master BP to understand the returned values)
Get Item Count: Returns you the Amount of all Items of a certain Class in your Inventory.
Target: Reference to the Inventory Actor
Class: The Item of wich you want to grab the Amount.
Result: False if no Item of the class could be found.
Amount: The Amount of the speciefied Item in your Inventory.
Customize & Add Items
If you need any more Item Specific Properties edit the “Item_Master” Blueprint and add the Variables of the desired Datatype to the Blueprint (Graph Tab). You will also have to modify the “Get Item Data from Class” Function inside of the “Inventory_Actor” to be able to return those Values with the function.
As for Adding Items you will create a Blueprint for every Item you want to create. IT IS IMPORTANT THAT YOU CREATE THAT BP OF THE “Item_Master” CLASS!
After you are done with that. Open the created Blueprint and edit its default Values. Those should be self explanary.
Thats it now you have a new Item you can add to your inventory.
The Master_Item BP also has a Event “Use” wich you can override in every single Item to create a custom behaviour for every item. To use the “Use” event you would spawn an item of the desired Item Class (not the Master_Item Actor) and then simple call the “Use” event on that freshly spawned item.
If you have any Questions feel free to ask them, i tried to document the BP-Nodes as good as posible. Ill try to help you as good as i can.
If you find any Bugs please Contact me so i can remove them from the script.
I did my best to design this thing so you dont have to deal with stuff like checking if there is space in the inventory and so on. You just add/remove etc and check if the action was successfull thats all.
And lastly this thing is free as i said, but if you feel genereous you could tip at paypalxD.
Oh… The Download =)
https://www…com/s/0jeyx8jaf9o7gmi/rInventory.zip?dl=0
C++ Version!