UE4 | Inventory for Multiplayer # 3 | Interaction structure
UE4 | Инвентарь для Multiplayer #1 | Хранилище данных на DataAsset
UE4 | Инвентарь для Multiplayer #2 | Подключение Blueprint к C++
UE4 | Инвентарь для Multiplayer #3 | Структура взаимодействия
UE4 | Инвентарь для Multiplayer #4 | Создание и подключение конейнера
UE4 | Инвентарь для Multiplayer #5 | Передача информации между Сервером и Клиентом
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:
- 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.
- The number of objects in the slot specified by the variable int .
- 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.
- 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 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.