Slots / Overflow

What is Overflow?

Overflow is what we call the items that don’t have an available storage slot during an add item event on our storage component. By default the subsystems will check to see if there is room before processing the request, and if there isn’t room the player will be notified with an alert.

There are some scenarios where items can still be added to the inventory without performing this check.

For example, in our demo world when a piece of raw meat spoils it creates spoiled meat, another item. What if there is no room for the spoiled meat? Since spoiling occurs in its own process there is no notice to the player and the process is not stopped, instead we handle what happens using an overflow policy (which defines what should happen).

Another example would be a loot box. While there is a setting to require X amount of slots before opening the loot box, you can still end up generating more items then there are slots for if you're not also using the max items variable. In this scenario what should happen to the extra items? Again, this is where our overflow policy steps up and handles what to do.

Player Overflow Policy

For the player we define the overflow policy on the AC_InventorySystem component we added to the player controller.

Here are the variables on the AC_InventorySystem added to the player controller that handle overflow:

InventoryOverflowPolicy - (Default: Drop on Ground) For the player’s inventory.
HotbarOverflowPolicy - (Default: Drop on Ground) For the player’s hotbar.
BankOverflowPolicy - (Default: Destroy Items) For the player’s bank.
EquipmentOverflowPolicy - (Default: Drop on Ground) For the player’s equipment.

Using these variables we can define what happens when items overflow in our Inventory, Hotbar, Bank, and Equipment. For each of these player related variables the following values are possible:

Drop on Ground - Items will be dropped on the ground near the player if they have a drop item handler. If they do not have a drop item handler they will be destroyed. This is the default action.
Destroy Items - Items will be destroyed.
Send to Inventory - Sends the item to the player’s inventory.
Send to Hotbar - Sends the item to the player’s hotbar.
Send to Bank - Sends the item to the player’s bank.

Non-player Overflow Policy

For any other non-player actor with a storage component you will not get the Send to Inventory, Hotbar, Bank options, but instead an option to Send to Overflow Storage Component, which lets us send the item to another storage component that we define at runtime using the setOverflowPolicy function on the storage component.

Under the surface the player specific settings are using this function during initialization.

Infinite Loop Mitigation

You may have noticed that this type of logic can end up causing an infinite loop to occur.

For example, lets say you set your Inventory to overflow to your Hotbar, and your Hotbar overflows back to your Inventory. Under normal circumstances you would get caught up in an infinite loop, which would cause the game to crash.

To mitigate this I’ve implemented an infinite loop buster, that in short will count the attempted iterations on the individual storage component, and after enough have occurred, the overflow policy will break out of the infinite loop and force the items to use the Drop on Ground method.