Equipment Component - NEW {{ currentPage ? currentPage.title : "" }}

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:

    1. Inventory: A list of items currently in the character's inventory.

    2. Equipment: Tracks equipped items and their respective slots.

    3. MaxInventoryWeight: Maximum weight capacity of the inventory.

    4. MaxInventorySlots: Maximum number of slots available in the inventory.

    5. currentInventoryWeight: Tracks the current weight of all items in the inventory.

    6. CharacterOwner: Reference to the owning character.

    7. MainCharacterMesh: The skeletal mesh of the character for attaching equipment.

  • Key Methods:

  1. 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.

  2. 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.

  3. Item Usage

    • UseConsumableOnActorBySlot(FGameplayTag, ACharacter*): Uses a consumable item on a target character.

    • CanUseConsumable(FInventoryItem): Checks if a consumable item can be used.

  4. 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

  1. Call AddItemToInventory or AddItemToInventoryByClass.

  2. Optionally auto-equip the item based on its type and slot availability.

Equipping Items

  1. Call EquipItemFromInventory.

  2. The system checks for slot availability and item requirements.

  3. If valid, the item is equipped and attached to the character mesh.

Unequipping Items

  1. Call UnequipItemBySlot or UnequipItemByGuid.

  2. The item is removed from its slot and returned to the inventory.

Using Items

  1. For consumables, call UseConsumableOnActorBySlot or UseEquippedConsumable.

  2. 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.

{{{ content }}}