# Inventory system with unique item issue, what did I miss ?

**URL:** <https://forums.unrealengine.com/t/inventory-system-with-unique-item-issue-what-did-i-miss/1848079>\
**Category:** Blueprint\
**Tags:** unreal-engine, question\
**Created:** [May 9, 2024, 2:34pm UTC](https://forums.unrealengine.com/t/inventory-system-with-unique-item-issue-what-did-i-miss/1848079 "2024-05-09T14:34:10Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [May 11, 2024, 12:41am UTC](https://forums.unrealengine.com/t/inventory-system-with-unique-item-issue-what-did-i-miss/1848079/8 "2024-05-11T00:41:18Z")

</div>

> [@Morph12345](#):
>
> The problem is there, if a weapon is in my inventory it’s not spawn in the world and this is my main issue, how to keep those dynamic information in something that is not an actor (because it’s not in the world) and not a struct (because I can’t mix different struct in the same inventory array on my character).

Keep the information stored as a struct in an inventory component and put that component on your pawn. Anything dynamic goes in that struct. anything constant goes in a datatable. spawned “items” such as weapons don’t hold state relevant to the inventory.

I don’t think you need to mix structs for anything in the inventory. If you have a rifle that requires 3 bullets to shoot you just let the rifle check the inventory component for the rifle and reserve 3 bullets?

I got very far by using a generic sounding attribute like “durability” for cases such as water in a bucket and durability on a rifle. Anything non generic would bloat the entire system but can probably be avoided.

- Edit

What about using JSON? This is one of those very rare cases I’d just like the flexibility of javascript to build structures / objects from scratch without being bound to a certain format. You will want it when you want the possibility for 9999 item types without pre programming them into a framework bloating it just in case.

I must say I haven’t tried this in c++ but why not 🙂 . I’m making the assumption this does not require you to convert between struct and json.

> [https://www.youtube.com/watch?v=4wJ45mrzrkM](https://www.youtube.com/watch?v=4wJ45mrzrkM)

> [How to retrieve single text field from Json? - #3 by GraeChan](https://forums.unrealengine.com/t/how-to-retrieve-single-text-field-from-json/350876/3)

> [@Rev0verDrive](#):
>
> For example you can use GameplayTags as ItemID
> 
> Items  
> Items.Weapon  
> Items.Weapon.AK47
> 
> An ID of _Items.Weapon.AK47_ tells me the Actor is a world item (player can add it to inventory). It’s a Weapon and it’s an AK47.

What I did was linking datatables. If an item’s datatable entry contains a pointer to another datatable “weapon datatable” containing the weapon specs, it is a weapon. The downside is this assumes there will be weapons in the game it is used in, making it less fit as a generic framework. Upside is you have all the data linked, bit like expanding data on the original struct into sub categories of an item.

---

_[View the full topic](https://forums.unrealengine.com/t/inventory-system-with-unique-item-issue-what-did-i-miss/1848079)._
