X157 Dev Notes

One simulant attempts to share insight with others.

LyraStarterGame Weapon System

This is an overview of the Weapon System in LyraStarterGame.

A Lyra weapon is a specialized piece of equipment based on the Lyra Equipment System, which itself is based on the Lyra Inventory System. Make sure you are familiar with those concepts as well.

Weapon Concepts

Weapon Instance

A Weapon Instance (ULyraWeaponInstance) is an Equipment Instance that also has equipped and unequipped animation sets associated with it.

It also keeps track of how long it has been since the player last interacted with it.

Most of the implementation is in the BP B_WeaponInstance_Base, from which all other Lyra Weapon Instances are derived:

The Weapon Instance has a Tick() method, which is executed every tick if/when the weapon is equipped by the Pawn. This ticking is managed by the Pawn Controller’s Weapon State Component.

Ranged Weapon Instance

A Ranged Weapon Instance is derived from Weapon Instance and implements ILyraAbilitySourceInterface.

It adds the concept of bullets, shot accuracy and spread, etc.

Weapon State Component

ULyraWeaponStateComponent goes on the Pawn Controller.

This component:

Weapon Debug Settings

ULyraWeaponDebugSettings is an implementation of a new UE5 feature, UDeveloperSettingsBackedByCVars.

Definitely read this class if you want to have similar functionality in your game, which I recommend since this makes gameplay debugging significantly easier.

Lyra supports the option to compile out weapon debugging, good for production. When developing a ranged weapon you should absolutely turn these debugging features on unless you like to needlessly waste your own time.

Weapon Spawner

This is a pad with a fixed position that spawns weapons based on the Weapon Definition you configure it for. You can set Cooldown time, the mesh of the weapon to show that will be picked up, etc.

This C++ class is implemented such that the core functionality of actually giving the weapon to the pawn MUST be implemented in Blueprints. There are 2 BP implementations:

Melee Attack Ability

GA_Melee is the Melee Attack Ability, derived from GA_AbilityWithWidget, which itself is based on ULyraGameplayAbility.

It is implemented such that it can be executed regardless of the type of weapon equipped, provided that weapon derives from B_WeaponInstance_Base (BP constraint).

Note that this ability is not derived from the base Equipment Ability (ULyraGameplayAbility_FromEquipment). While this makes sense in that equipment isn’t necessarily required to melee (Pawns have fists, feet, heads, etc), it also means that in the current implementation there is no way to make a Katana melee for more than a fist. This seems like a significant implementation flaw. You should absolutely change this if you want interesting melee gameplay.

On Melee Attack:

Ranged Weapon Base Ability

ULyraGameplayAbility_RangedWeapon derives from the Equipment System’s Equipment Ability (ULyraGameplayAbility_FromEquipment), giving it easy access to the specific weapon that is responsible for granting the ability to the player, which will be equipped at the time of ability activation.

This is the base class for all Lyra Ranged Weapons, and is implemented by:

As seems to be the standard for Lyra Gameplay Abilities, very little is done in C++ and most of the implementation is in the BP, in this case GA_Weapon_Fire which is the base BP for ranged weapons.

If you’re interested in how weapons work in Lyra, definitely study the event graph of GA_Weapon_Fire to see how it works.

On Ability Activation (on firing the weapon):

Additionally, ranged weapons will listen for “failed to fire weapon” Gameplay Events (Ability.PlayMontageOnActivateFail.Message) and play an animation montage to help the player visualize the failed ability activation. That Gameplay Message is broadcast by the base ULyraGameplayAbility::NativeOnAbilityFailedToActivate.