UE4 | Inventory for Multiplayer # 3 | Interaction structure

  • Tutorial



In this article we will look at the inventory structure, which I applied for my multiplayer project. This section is quite small and does not contain the code.


The inventory itself is a component used not only for Character , but also for any object in the game, which according to the scenario can be a repository for objects. For example: chest, drawer, box, cabinet, etc.




This component contains a TArray , whose elements store the minimum necessary information:


  1. The object identifier, in the form of a GameplayTag . As I said earlier, GameplayTag is more convenient than, say, FName , as it significantly reduces the risk of error.
  2. The number of objects in the slot specified by the variable int .
  3. Category object to understand how it can be applied. For this purpose, you can use GameplayTagsContainer instead of Enum , which will allow us to attribute the object to a set of types at once if necessary.
  4. Unique properties of the object, which are stored as a structure from the GameplayTag and float bundles . Here you can store both parameters and modifiers.

In this inventory structure there are no references to the objects themselves, because after saving and loading the game, they will refer to areas that already store other data. Thus, some kind of tool is needed that could restore (respawn) all objects after loading the game. This is where DataAsset comes to the rescue , which is always available on the server side (since in our case we connected it via GameMode ) and is ready to help place the object on the stage.


The component of the inventory also contains the logic of removing and adding the required number of objects, the logic of filling slots. All functions launched in the container should work only on the server side.


The structure of the interaction of inventory and database is as follows

The unique properties of the object, such as additional components , and the logic can be easily configured using C ++ and / or Blueprint .


In the next section, I will show how you can connect the created component to Character or any other object.


Any constructive criticism is welcome. Preferably backed up with suggestions.


PS The first two articles added explanatory images.


Also popular now: