Item System Design


1 Framework Design


The item system is one of the most important systems in our project. Most of the features of the character can be driven by the obtained items. For example, after obtaining weapon item, the weapon system is activated and the character will have weapon’s features.

The structure of item system is given below.

systemstruct

The item system mainly includes the following parts:

  • Item Entity(BP_ItemEntityBase_USG)

    • Item entity is mainly used to define the attributes and functional interfaces of different items. We define the base class of item entity and derive it according to the features of different items.

    • The item entity class contains the basic attributes such as ID, type, weight, as well as the interfaces, including gain, use, disuse, discard.

  • Pickup Entity(BP_PickupEntity_USG)

    • Pickup entity is the actor in the scene, whhich has the configured properties, including item ID and item count.

    • After picking up the entity, the corresponding items will be stored in item manager. If it is configured as automatically using, it will be automatically used while obtaining items, and the use item interface is automatically called.

    • After the items are discarded, the pick up entities will be regenerated next to the character on the ground.

  • Item Manager(BP_InventoryManager_USG)

    • As a component of player controller, it contains basic interfaces such as AddItem, DiscardItem, UseItem, DisuseItem.

    • It is used to store and maintain all the items on the character. The interfaces of the item entity is only triggered on the authorization side(e.g. Dedicated Server) and activate different systems, such as weapon system.

    • It is responsible for synchronizing the items to the clients. The item entity instance is created by default on authorization side(e.g. Dedicated Server), and the clients only makes some display for these items.

  • Item Definition Table

    • The item table is used to configure item ID, item type, item weight, item description, equippable, cumulative and consumable features.

    • For equippable item, it cannot be consumed because it can be equipped and unequipped.

    • The non-cumulative items will generate the item entity instance alone for each item, and the count can only be 1. For cumulative items, the items will be split according to the cumulative limit.

2 Core Data Structures


2.1 Item Entity


If you want to define the type of new items, you need to derive from BP_ItemEntityBase_USG and implement the following interfaces.


  • OnGained: When obtaining items, you can do some initialization operations.

  • OnCountChanged: The Callback function when current item count changed.

  • TryUseItem: The interface triggered when item used.

  • TryDisuseItem:The interface triggered when item disused.

  • TryDiscardItem:The interface triggered when item discarded.


2.2 Pickup Entity


If you want to define the type of pickups, you need to derive from BP_PickupEntity_USG and fill following properties.

  • DefaultPickupList: The list of item id that can be picked up. The item id is configured at the item table.

  • IsAutoPickup: If true, the items will be auto picked up when the player overlap this pickup actor.

  • IsDestroyAfterPickup: If true, this pick up actor will be destroyed after all items are picked up.

  • Sphere: Config the sphere radius for overlapping. Listening to this event to show display ui.


2.3 Item Manager


For the use of items management (BP_InventoryManager_USG), you can mainly focus on the following properties and methods.

  • LogicItemList: The replicated List of all items, mainly stored all items ID and status and used to synchronize items to the clients.

  • AllItemEntities: All items entities, which are only existing on the authorization side, please do not use this list on the client.

  • PickupEntities: All pickup entities nearby the character.

  • OnPickupsChanged:The event that will be called when the pickups changed.

  • OnItemsChanged: The event that will be called when the item list changed.


2.3 Other API


Click here to view more APIs.


3 Development Flow


See “The Usage of Item System”.