Overview
The ACF Equipment Component is a core part of the ACF Item System, designed to handle inventory management, equipment functionality, and item interactions in a game built with Unreal Engine. This system allows characters to equip, unequip, and use items while managing an inventory with weight, slots, and replication support for multiplayer environments.
Core Features
Inventory Management: Add, remove, and manage items in an inventory with weight and slot limitations.
Equipment System: Equip and unequip items, supporting various item types (weapons, armor, consumables, etc.).
Item Interactions: Use consumables, manage modular character meshes, and handle weapon attachments dynamically.
Multiplayer Support: Fully replicated to ensure proper synchronization across the network.
Key Classes and Components
UACFEquipmentComponent
This is the main component for managing inventory and equipment.
Properties:
Inventory: A list of items currently in the character's inventory.
Equipment: Tracks equipped items and their respective slots.
MaxInventoryWeight: Maximum weight capacity of the inventory.
MaxInventorySlots: Maximum number of slots available in the inventory.
currentInventoryWeight: Tracks the current weight of all items in the inventory.
CharacterOwner: Reference to the owning character.
MainCharacterMesh: The skeletal mesh of the character for attaching equipment.
Key Methods:
Inventory Management
AddItemToInventory(FBaseItem, bool bAutoEquip): Adds an item to the inventory, optionally equipping it.
RemoveItem(FInventoryItem, int32 count): Removes a specified quantity of an item from the inventory.
DropItem(FInventoryItem, int32 count): Removes an item from the inventory and spawns it in the world.
FindItemsByClass(TSubclassOf<AACFItem>): Finds all items of a specific class in the inventory.
HasEnoughItemsOfType(TArray<FBaseItem>): Checks if the inventory contains enough of the specified items.
Equipment Management
EquipItemFromInventory(FInventoryItem): Equips an item from the inventory.
UnequipItemBySlot(FGameplayTag): Unequips an item from a specified slot.
SheathCurrentWeapon(): Sheathes the currently equipped weapon.
UseEquippedItemBySlot(FGameplayTag): Uses an item equipped in the specified slot.
RefreshEquipment(): Updates the modular character mesh and equipment.
Item Usage
UseConsumableOnActorBySlot(FGameplayTag, ACharacter*): Uses a consumable item on a target character.
CanUseConsumable(FInventoryItem): Checks if a consumable item can be used.
Networking
OnRep_Inventory(): Called when the inventory is replicated to update the client.
OnRep_Equipment(): Called when equipment is replicated to refresh the equipment state.
Equipment and Inventory Workflow
Adding Items
Call AddItemToInventory or AddItemToInventoryByClass.
Optionally auto-equip the item based on its type and slot availability.
Equipping Items
Call EquipItemFromInventory.
The system checks for slot availability and item requirements.
If valid, the item is equipped and attached to the character mesh.
Unequipping Items
Call UnequipItemBySlot or UnequipItemByGuid.
The item is removed from its slot and returned to the inventory.
Using Items
For consumables, call UseConsumableOnActorBySlot or UseEquippedConsumable.
For equippable items, use EquipItemFromInventory or SheathCurrentWeapon.
Replication
The component ensures inventory and equipment data are synchronized across the network:
Inventory and equipment states are replicated
OnRep_Inventory and OnRep_Equipment handle client-side updates.
Customization and Extensibility
Item Classes: Extend AACFItem and its subclasses (AACFWeapon, AACFArmor, AACFConsumable, etc.) to define custom items.
Slot System: Use gameplay tags to define and manage equipment slots.
Mesh Customization: Integrate modular character meshes with UACFArmorSlotComponent.
Examples
Adding an Item to Inventory
EquipmentComponent->AddItemToInventory(NewItem, true); // Automatically equips the item if possible
Equipping a Weapon
FInventoryItem WeaponItem;
if (EquipmentComponent->FindFirstItemOfClassInInventory(WeaponClass, WeaponItem)) {
EquipmentComponent->EquipItemFromInventory(WeaponItem);
}
Using a Consumable
FGameplayTag ItemSlot = ...; // The slot of the consumable
EquipmentComponent->UseConsumableOnActorBySlot(ItemSlot, TargetCharacter);
This system provides a flexible and efficient way to manage inventory and equipment while ensuring compatibility with multiplayer environments. It is highly modular, allowing for seamless integration with other ACF components.