Figure 12.
Later, new useful functionality was added to take out specified amount of objects. Override method of TakeObjectFromBackPack(string objectKey, int amount) was created, that iteratively will call TakeObjectFromBackPack(string objectKey) until object amount becomes zero. If given amount is greater than available object amount, recursion will be stopped after all existing objects are dropped.

4.4 Removing all objects from the backpack

It is useful to drop all items from the backpack, considering player’s time (if he or she wants to drop all items out) and that items can be taken away, lost or any other in video-game possible situation. Function ThrowoutAllObjects() was created in iterative fashion, without the use of loops. Function will call itself after a single item was dropped out to drop the next item. Before it calls itself, it does few checks and adjustments of dictionaries. To track how many items and how many ObjectTypes remains, after dropping a single item, dictionaries are adjusted as in 4.3 Retrieving the object from the backpack.
As in majority video-games, a quest items (in our case the specialItem) cannot and should not be removed from the backpack by the player this was also implemented in this backpack system. The check and implementation of special object was problematic. Multiple approaches were considered, one of those was to skip special item if it is found. Then, function would call itself, with a different Key and try to remove that object. However, it appeared that the constant check if item was special and empty recursive function call (if there is a huge cluster of special items) was not needed. It was decided to store special items in the beginning of the dynamic List objectTypes and when recursive function hits the first special item, function stops. After that, the only remaining items that stays in the backpack are the specialItems.

4.5 Puting initial objects into the backpack

When experimenting, and placing huge initial amounts of object into the backpack, Unity GUI limits were reached (errors were given), as a huge amount of objects were shown in the Inspector, where they were placed. It was realized that this is not a smart approach. Second list initialBackPackObjectAmount that holds amounts (integer) of initially placed objects were created, see picture XXX. Therefore, a single object could be placed in the inspector, and amount of such objects indicated by that integer. After, code was adjusted to not to loop (initially on start) through  this amount when adding new items. Instead initialBackPackObjectAmount array numbers were reflected to backPackObjectAmount(Key) dictionary, when initial objects were inserted. More convenient and clean method would be to access the dictionary directly from the Inspector and two additional lists of initial gameo bjects and amounts would not be required. However, Unity currently does not support serialization of dictionaries (used in the inspector, to reflect properties held in the data types), therefore, dictionaries are not accessible through the Inspector.

4.6 Inventory GUI

The new backpack system received the graphical user interface (GUI) showing how objects are grouped, named and counted. This required to create some graphical elements as object icons, basic inventory background and text fields. Since the grouping, object count and naming was prepared by the dictionaries, only remaining implementation was to display this information on-screen to the player. This required the creation of numeric grid (pre-defined positions for icons) to store the icons when player turns on the inventory. Picture below shows how the inventory GUI functions. Three different green apples are in different sizes or weights, therefore they are grouped as different objects.