Problems with my simple inventory system style Hello Neighbor (Attach/Detach)

Hello, good afternoon.

I’m trying to create a very simple inventory system, similar to the one in “Hello Neighbor”.

The idea is that the player can pick up, drop, and swap between objects (without destroying or creating new actors).

I don’t want to use “Structures” or “Data Tables”, just basic functions like “Attach”, “Detach”, “Set Hidden in Game”, and Arrays.

I’ve watched many tutorials, but they all use complex systems (with Spawn/Destroy Actors. Data Tables, etc.), and I’m looking for something more straightforward.

With the help of ChatGPT, I’ve made a lot of progress, but we’ve run into some bugs that we can’t seem to solve.

I share with you my actual configuration, there is 4 functions that i made with the help of the IA inside of the BP Player.

“PickupItem”

“UpdateHeldItem”

“DetachHeldItem”

“DropItem”

And 4 variables.
“Inventory (Array Actor 5 slots)”
“CurrentHeldItem (Actor)”
“SelectedSlotIndex (Index)”
Local in UpdateHeldItem “SelectedItem (Actor)”

I have 3 problems.
The first, is in the function “Pick up Item” they don’t have a Loop then verificare the empty slots of the inventory. This causes it to skip slot 2 and go directly to slot 4 if slots 2, 4, and 5 are empty. I tried to fix this with the help of AI, but its solution didn’t work.

The second.Is when the player drop a object, the information in the array get “Deleted” but in the index not. This causes the inventory to appear full if I pick up and drop an item 5 times and then try to pick it up again, despite they dosent have any object in the inventory.

The third, is more like verification, when the game start, the inventory appears like full despite they doesn’t have any object in there. The solution that give me the IA is use “Clear Array” of inventory in “Event Begin Play” and i dont know if is the correct way.

I only need a basic system with:5 visible spaces (images or icons)Grab, drop, and switch using keys 1 through 5No Spawn or Destroy Actor, just Attach/Detach

I appreciate any help or guidance.

If the current system is too confusing, I wouldn’t mind redesigning it from scratch with your input, as long as it remains as simple as possible. PS the english is not my native language If i made any mistakes in my writing i apologize in advance.

Thank you for your time.

Regarding question 1, the core issue is the non-trivial logic required to locate an available inventory slot for a new item. A clean solution involves encapsulating this logic within a GetSlotIndexToInsertPickupItem function. This function should iterate over the inventory array and return the index of the first empty slot, which then dictates the insertion point for the picked-up item.

Regarding question 2, the choice of data layout is key. Generally, you have two options:

  1. Use a fixed-length array(e.g., of size 5). When an item is dropped, you simply clear the corresponding slot.

  2. Use a dynamic array. When an item is dropped, you remove the element entirely.

The fixed-length approach preserves slot indices, making it easier to track item positions, while the dynamic approach is simpler to implement. Both are valid strategies.

Regarding question 3, as explained earlier, an item array with 5 empty slots should not be considered “FullWeapon”. Instead, you should implement functions like IsInventoryFull(which returns a boolean) and GetEmptySlotIndexto manage the inventory’s state. This function-driven approach is the core concept of a proper inventory system. It’s essential to think through the data management strategy before building the system.