Attachable Inventory System
An Unreal Engine Blueprint based Inventory system with attachable mesh objects, interactions, and item save functionality
Capabilities & Features
- Player Inventory framework
- Item Pickup/ drop/ dismantle
- 3D Model inspection view
- Drag and Drop 2d menu to 3d objects/world
- Combine/Assemble and Disassemble items in menu or in world
- Save/load System to handle Player inventory and world item states
- Mobile touch and PC mouse controls ready
- Object Outlining Post Process on selection
8 Example Inventory Objects and Attachments
(Includes: blueprints, meshes, materials and 2d artwork)
Pickup-able Rifle with attachable scope and magazine
Pickup-able and Power-able Data Tablet with Attachable power cell, Data Card,
Computer Console with slots for data cards and fuses and Data Tablets
1 Demonstration Map
& Debug Tools
Demo map with all objects
Select and Spawn Items from the included tools menu
(sourced from debug spawntable, data table)Save Game state ( reloads automatically on level load)
Delete Save Game
Using the System
Directly Selecting the static mesh of an item derived from Item_Base will present a context menu. When on the ground or in the Environment this will allow you to pickup said item. When inside the inventory menu this will allow you to remove attachments of said objects.
Once an object is selected in the inventory you can rotate the model by clicking (or pressing) on the model and moving your input device to expose attachments for selection.
To Insert or attach objects, have the destination item selected and simply drag the item from the inventory onto that object. This works both for items in your inventory and in the world.
You can also drop or dismantle objects by long clicking/holding on the item in the inventory list.
The Debug tools menu allows basic selection of items listed in the debug spawn-table for easy spawning, as well as save file controls.
Migrating to your Project & Setting it up
- Migrate the "Attachable Inventory System " folder to your project.
- If you are using your own player character, open the Attachable_Item Character and copy the highlighted blueprint diagram and paste into your character file (make sure to account for used variables). Then add the required "Inventory_Component" component to your character via add component menu.
- You will also need to copy the ItemSpawn arrow component out of the Attachable_Item_Character and place it into your character. This component is referenced by the Inventory_Component and dictates where the 3D model of the item will spawn in relation to your player camera. Note how it is a child of the camera.
- If you would like to use the basic item rotation code availble by default in your own project, you will need to copy it out of the provided "Item_PC" and paste it into your player controller (make sure to account for used variables).
Object outlines require use of post processing, you can inspect the "Item demonstration" level and find the post process volume used for this as well the "m_outline" material used for the effect.
System Overview
Important Objects
- Inventory Component, actor component: Handles primary logic for item system, it is placed in your character
- Attachable_Item-Character, Character: Default bare bones character, should be replaced with your character class.
- Item_PC, player controller: The default player controller contains several prebuilt blueprint scripts. You can start with this PC as you player controller or copy and paste these scripts ( make sure you account for the variables used here if copy and pasting )
- Touch based basic item rotation in inventory menu
- Item highlight clearing on unselect.
- Basic player movement controls
- Item_Base:
- Item_Attachment:
- AttachableInventory_SaveSystem:
Items, Attachments, & Devices
Common language you will run into refers to Items, Attachments & Devices. An Item is a generic term to describe any object (this could be a base item like a rifle body, or a scope, or a magazine). Attachments are items that are to be inserted into another item( think a scope being applied to a rifle) . and a device is used in refer to an item that includes attachments that can be inserted into another object ( think a fully kitted gun being stowed in a weapon rack).
Making New Inventory Objects & Attachments
(Base Item Editing)
Setting up your new Item
Item_Base contains a variable Called "Item_Info" which is a Iventory_Item_Struct this is where all required information lives.
Item_Info & Inventory_Item_Struct: Variables, Public
Class, class ( Used in logic )
- Name, string (Used in UI)
- Condition, float (used in logic)
- Description, string (Used in UI)
- Mesh, static mesh (Used in game)
- Image, texture2D (Used in UI)
Attachments and devices are optional. However, if added each variable must be filled out completely.
- Attachments, Item_Slot_Struct Array: Used in placement logic. It contains the following variables.
- Slot_Occupied, bool: Used in attachment placement logic
- Slot_Socket_Name, string: Used in attachment placement logic. This is the Socket the attachment will be placed at defined in the static mesh.
- Class, class ( Used in logic )
- Name, string (Used in UI)
- Condition, float (used in logic)
- Description, string (Used in UI)
- Mesh, static mesh (Used in game)
- Image, texture2D (Used in UI)
- Devices, Device_Inventory_Struct Array (Used in placement logic - This is used in case a complete object with attachments is to be attached/placed, rather than just an individual item.
- Pickup-able Item, bool (Determines if this item can be picked up by a player, used to create in world items like consoles, )
- Simulate Physics, bool (used in game to stop the item from being impacted by gravity, used to place objects onto other static objects)
Variables: Internal
- Char_ref, attachable_Item_Char (This should be changed to your character class)
Creating Attachment Sockets
This system uses static mesh sockets to position the attachable meshes. You can create the attachment sockets in Unreal via the Static mesh editor, or if you have access to the mesh source file, sockets can be added and exported along with the mesh by using "dummy" or "empty" objects named "SOCKET_DesiredName". after successful export and import into Unreal, all added sockets will be visible and listed in the socket panel for further editing if needed.
Tip:You can optionally select the preview mesh in the static mesh socket panel to better align how your attached mesh will fit on your mesh.
Adding Additional Item variables.
Depending on what the item is, you may find that you need more specific variables than the default provided.
First you will need to add the new variable to all 3 of the following
- Inventory_Item_Struct
- Item_Slot_Struct
- Device_Inventory_Struct
Then create the additional required connections in the Inventory_component Blueprint. This is what passes the item_info from one object to the next when being "placed". as well as create additional connections in the Item_Base blueprint.
There are two places in each of these that will need updating, one for attachments and one for devices.
inventory_component
Extending Item Functionality
You can add additional functionality to an item such as powering on an object or making an overall condition modifier to children of Item_base. Open Item_tablet for an example of creating a simple power on check.
Save/Load Item System
The save system by default only accounts for objects derived from Item_Base. It is accessable via the "Inventory_component" in the Attachable_Item-Character it is useable via direct call in blueprint code (Save Game, Load Game), as well as a button in the tools menu.
This system saves the contents of the player inventory as well as the specific state of an item and it's attachments in the inventory.
It also saves and loads the state of Item_Base actors that are placed or dropped in the world.
On Load both player inventory and world items are populated
Note:
Editing blueprint logic with an exsisting save file is known to create anomalies in the save/load system. For the best results make sure you are deleting the save game object before testing.