X157 Dev Notes

One simulant attempts to share insight with others.

LyraStarterGame Equipment System

This is an overview of the Equipment System in LyraStarterGame.

A piece of Equipment in Lyra is an Inventory Item that has a particular Item Definition Fragment that identifies it as being Equipment. Thus, this system is based on the Lyra Inventory System, so make sure you’re familiar with that as well.

The Lyra Equipment System is the base for the Lyra Weapon System.

Note that although the Equipment Definition and Equipment Instance share a naming convention with the Inventory Definition and Inventory Instance, the relationship between the objects is different. This is potentially confusing, so be aware of it.

Equipment Concepts

Equipment Definition

This is a simple constant config. There is no functionality associated with a ULyraEquipmentDefinition, it’s just data.

An Equipment Definition consists of:

Equipment Instance

ULyraEquipmentInstance handles spawning and destroying the equipment actors as needed for a given piece of equipment.

Note that unlike the Item Instance, an Equipment Instance subclass is actually a required part of the Equipment Definition. Thus it is not only an instance of the Equipment Definition, but it is also a dependency of it, which is kind of weird.

Equipment Manager

ULyraEquipmentManagerComponent is a Pawn Component. It must be attached to a Pawn.

The Equipment Manager keeps track of the equipment this Pawn currently has available and allows for the Pawn to equip or unequip any given piece of equipment. It uses FLyraEquipmentList to achieve this. The owner of the FLyraEquipmentList is the Equipment Manager itself.

It invokes Equipment Instance -> OnEquipped() and OnUnequipped() as appropriate.

The core functionality is implemented in the EquipItem method.

Pickup Definition

This is kind of weird because they implemented base Inventory Item Pickup in the same place as Weapon Pickup.

In any case, the Pickup Definitions define things like:

QuickBar Component

Controls which item the Pawn has equipped.

Note that in Lyra the QuickBar Component is required to be able to use equipment. While this works fine in Lyra’s simple ShooterGame concept, I can’t say I’m a huge fan of this design choice.

The key to Lyra’s QuickBar-based Equipment System is ULyraQuickBarComponent::SetActiveSlotIndex_Implementation, which is the only piece of code in Lyra that causes equipment to be equipped or unequipped.

SetActiveSlotIndex_Implementation calls UnequipItemInSlot (unequip item in old slot, if any) followed by EquipItemInSlot (equip item in new slot, if any). In both cases the under-the-hood work is performed by the Equipment Manager.

The QuickBar Component has virtually no utility for AI Bots and yet every Bot is forced to have one. In my game, there are WAAAAAY more Bots than there are players, and so having to put components that are only useful for players on every Bot is fairly inefficient in my case. It seems rather easy to remove this dependency, and so in my own Equipment System implementation, that is what I plan to do.

Equipment Ability

ULyraGameplayAbility_FromEquipment is provided as a new Base Ability class for Equipment-related abilities.

The key functionality provided here includes:

The Associated Equipment SourceObject value is assigned by FLyraEquipmentList::AddEntry during the construction of the Equipment Instance.

Thus any Ability deriving from this base (or implementing similar functionality) can easily access the underlying Weapon Instance and its base Item Instance.

The Associated Equipment Instigator value is assigned by ULyraQuickBarComponent::EquipItemInSlot whenever a piece of equipment is chosen to be equipped by the Pawn to be the underlying Inventory Item Instance.

Important Code to Consider

Particularly if you are going to be implementing a system similar to this yourself, the following is some important code that helps to support the equipment/weapon abilities.

You should consider this to understand how it helps support the system overall.

ULyraEquipmentManagerComponent::EquipItem

ULyraEquipmentInstance* EquipItem (TSubclassOf<ULyraEquipmentDefinition> EquipmentDefinition);

Called whenever a new piece of equipment should be equipped. An Equipment Instance is spawned based on the Equipment Definition.

The Equipment Instance is created via a call to:

FLyraEquipmentList::AddEntry

ULyraEquipmentInstance* AddEntry (TSubclassOf<ULyraEquipmentDefinition> EquipmentDefinition);