Skip to content

Weapon

Introduction

The weapon attached to characters

Dependencies

The Weapon relies on other components of this plugin to work:

  • Logger: Used to log useful information to help you debug any issues you might experience
  • Audio: Used to play sound effects either 2D or at a specified location

Components

The Weapon uses the following components:

Name Description Type
WeaponMesh The skeletal mesh of the weapon USkeletalMeshComponent*
MuzzleFlash The muzzle flash of the weapon USceneComponent*

API Reference

Properties

Property Description Type Default Value
WeaponType The type of weapon EWeaponType
WeaponFireMode The fire mode of weapon EWeaponFireMode
AimFov The FOV of the camera while aiming float 70
Crosshair The crosshair used by the weapon UCrosshairConfig* nullptr
FireRate The fire rate of the weapon (amount of seconds between each shot) float 0.2f
MaxShotsPerFireEvent The amount of shots fired per fire event int 3
Projectiles The projectiles spawned by the weapon TArray<FWeaponProjectileData>
bInfiniteAmmo Does the weapon have an infinite amount of ammo? bool false
bRequireReloading Does the weapon require reloading? bool true
bAutoReloadWhenFiringWhileEmpty Should the weapon automatically be reloaded when firing while empty? bool true
ReloadDuration The delay after reloading and before ammo is added to the weapon float 0.65f
Ammo The amount of ammo for the weapon int 50
AmmoPerClip The amount of ammo per clip int 20
WeaponAttachPoint The attach point used by all weapons FName
WeaponTransform The relative transform of the weapon after it is attached to a character FTransform
WeaponAimTransform The relative transform of the weapon while aiming FTransform
RecoilCurve The curve used to add recoil to the weapon UCurveVector* nullptr
RecoveryTime The recovery time after recoil was applied float 1.0f
RecoilRecoveryDelay The delay before we start recovering from recoil float 0.15f
bWeaponSway Should weapon sway be enabled? bool true
WeaponSwayMultiplier The multiplier applied to the weapon sway rotation float 1.0f
WeaponSwayInterpSpeed The speed used to interpolate the weapon sway rotation float 10.0f
FireCameraShake The camera shake applied when firing the weapon TSubclassOf<UCameraShakeBase>
MuzzleFlashParticleFx The muzzle flash particle effects UNiagaraSystem* nullptr
MuzzleFlashParticleFxTransform The transform of the muzzle flash particle effects FTransform
FireSound The sound played each time the weapon is fired TArray<USoundBase*>
EmptyClipFireSound The sound played each time the weapon is fired with an empty clip TArray<USoundBase*>
ReloadSound The sound played when the weapon is reloaded TArray<USoundBase*>
FireAnimation The animation played when the weapon is fired UAnimMontage* nullptr
EmptyClipFireAnimation The animation played when the weapon is fired with an empty clip UAnimMontage* nullptr
EquipAnimation The animation played when the weapon is equipped UAnimMontage* nullptr
ReloadAnimation The animation played when the weapon is reloaded UAnimMontage* nullptr
ReloadAimAnimation The animation played when the weapon is reloaded while aiming UAnimMontage* nullptr

Events

Name Description Params
OnWeaponEquipped Event used to notify other classes when the weapon is equipped
OnWeaponUnequipped Event used to notify other classes when the weapon is unequipped
OnWeaponFired Event used to notify other classes when the weapon is fired
OnWeaponFiredEmptyClip Event used to notify other classes when the weapon is fired with an empty clip
OnWeaponAmmoUpdated Event used to notify other classes when the weapon ammo is updated Weapon (AWeapon*)
The current weapon used by the character

Ammo (AWeapon*)
The amount of ammo remaining

ReloadAmmo (AWeapon*)
The amount of ammo that can be used to reload the weapon
OnWeaponAmmoEmpty Event used to notify other classes when the ammo is empty

Functions

Name Description Params Return
Equip Equip the weapon TargetCharacter (AUSKCharacter*)
The character that will use the weapon

IsNewWeapon (bool)
Is this a new weapon?
Unequip Unequip the weapon
StartFiring Start firing the weapon
StopFiring Stop firing the weapon
AddAmmo Add more ammo to the weapon Amount (int)
The amount of ammo to add
RemoveAmmo Remove ammo from the weapon Amount (int)
The amount of ammo to remove
GetAmmoRemaining Get the amount of ammo remaining int
The amount of ammo remaining
GetReloadAmmoRemaining Get the amount of ammo that can be used when reloading int
The amount of ammo that can be used when reloading
Reload Reload the weapon
StartRecoil Start applying recoil to the weapon
StopRecoil Stop applying recoil to the weapon
ApplyRecoil Apply recoil to the weapon DeltaSeconds (float)
Game time elapsed during last frame modified by the time dilation
StartRecoilRecovery Start recovering from recoil
StopRecoilRecovery Stop recovering from recoil
ApplyRecoilRecovery Recover from recoil DeltaSeconds (float)
Game time elapsed during last frame modified by the time dilation

Blueprint Usage

You can use the Weapon using Blueprints by adding one of the following nodes:

  • Ultimate Starter Kit > Weapon > Equip
  • Ultimate Starter Kit > Weapon > Unequip
  • Ultimate Starter Kit > Weapon > Start Firing
  • Ultimate Starter Kit > Weapon > Stop Firing
  • Ultimate Starter Kit > Weapon > Add Ammo
  • Ultimate Starter Kit > Weapon > Remove Ammo
  • Ultimate Starter Kit > Weapon > Get Ammo Remaining
  • Ultimate Starter Kit > Weapon > Get Reload Ammo Remaining
  • Ultimate Starter Kit > Weapon > Reload
  • Ultimate Starter Kit > Weapon > Start Recoil
  • Ultimate Starter Kit > Weapon > Stop Recoil
  • Ultimate Starter Kit > Weapon > Apply Recoil
  • Ultimate Starter Kit > Weapon > Start Recoil Recovery
  • Ultimate Starter Kit > Weapon > Stop Recoil Recovery
  • Ultimate Starter Kit > Weapon > Apply Recoil Recovery

C++ Usage

Before you can use the plugin, you first need to enable the plugin in your Build.cs file:

PublicDependencyModuleNames.Add("USK");

The Weapon can now be used in any of your C++ files:

#include "USK/Weapons/Weapon.h"

void ATestActor::Test()
{
    // Weapon is a pointer to the AWeapon
    Weapon->Equip(TargetCharacter, IsNewWeapon);
    Weapon->Unequip();
    Weapon->StartFiring();
    Weapon->StopFiring();
    Weapon->AddAmmo(Amount);
    Weapon->RemoveAmmo(Amount);
    int AmmoRemaining = Weapon->GetAmmoRemaining();
    int ReloadAmmoRemaining = Weapon->GetReloadAmmoRemaining();
    Weapon->Reload();
    Weapon->StartRecoil();
    Weapon->StopRecoil();
    Weapon->ApplyRecoil(DeltaSeconds);
    Weapon->StartRecoilRecovery();
    Weapon->StopRecoilRecovery();
    Weapon->ApplyRecoilRecovery(DeltaSeconds);
}