|
Weaponry Assembly System
WAS
|
#include <WeaponComponent.h>
Inheritance diagram for UWeaponComponent:
Collaboration diagram for UWeaponComponent:Public Member Functions | |
| void | BuildAsset (const UWeaponAsset *Asset) |
| FORCEINLINE void | CancelReload () |
| bool | CanTrigger () const |
| virtual bool | CanTrigger_Implementation () const |
| void | Clean () |
| FORCEINLINE void | ClearCache () const |
| DECLARE_FUNCTION (execSetAmmoSource) | |
| DECLARE_FUNCTION (execSetAmmoSourceFromMap) | |
| FORCEINLINE void | EndReload () |
| void | EnsureHasCharacteristics () |
| void | EnterTrigger () |
| FORCEINLINE bool | ExistSlot (FGameplayTag slot) const |
| void | ExitTrigger () |
| USceneComponent * | FindCachedSocket (FName Socket) const |
| USceneComponent * | FindSocket (FName Socket) const |
| void | GenerateInitializationData (FWeaponInitializationData &Data) |
| FORCEINLINE int32 | GetAmmoInMagazine (int32 Fallback=0) const |
| FORCEINLINE int32 | GetAmmoInMagazineOrSource () const |
| FORCEINLINE int32 | GetAmmoInSource (int32 Fallback=0) const |
| FORCEINLINE int32 | GetAmmoInUse () const |
| FORCEINLINE int32 | GetAmmoLoosePerTrigger () const |
| FORCEINLINE int32 | GetAmmoSource (const int32 Fallback=int32()) const |
| template<typename T > | |
| FORCEINLINE T | GetAmmoSource (const T Fallback=T()) const |
| FORCEINLINE TEnumAsByte< EAmmoType > | GetAmmoType () const |
| FORCEINLINE uint8 | GetBurstTriggers () const |
| USceneComponent * | GetCachedTaggedComponent (FName Tag) const |
| FORCEINLINE UWeaponAssetDefaultCharacteristics * | GetCharacteristics () const |
| FORCEINLINE UWeaponAssetCharacteristics * | GetCharacteristicsAsClass (TSubclassOf< UWeaponAssetCharacteristics > CharacteristicsClass) const |
| FORCEINLINE uint8 | GetCurrentBurstIndex () const |
| FORCEINLINE bool | GetCustomReloadExecutionTiming () const |
| FORCEINLINE bool | GetCustomTriggerExecutionTiming () const |
| FORCEINLINE bool | GetCustomUnjamExecutionTiming () const |
| FORCEINLINE const UWeaponAssetDefaultCharacteristics * | GetDefaultCharacteristics () const |
| FWeaponExecutionContext | GetExecutionContext (bool bRefreshNotifications) const |
| FORCEINLINE uint8 | GetIterationReloadStepAmount () const |
| FORCEINLINE float | GetJamProbability () const |
| FORCEINLINE bool | GetLooseExtraAmmoOnReload () const |
| FORCEINLINE int32 | GetMagazineAmmo (const int32 Fallback=int32()) const |
| template<typename T > | |
| FORCEINLINE T | GetMagazineAmmo (const T Fallback=T()) const |
| FORCEINLINE int32 | GetMagazineCapability () const |
| int32 | GetMagazineRemainingCapability () const |
| FORCEINLINE FGameplayTag | GetModificationAtSlot (FGameplayTag Slot) const |
| FORCEINLINE bool | GetReloadByMagazine () const |
| FORCEINLINE int32 | GetSourceAmmo32 () const |
| FORCEINLINE int64 | GetSourceAmmo64 () const |
| FORCEINLINE uint8 | GetSourceAmmoByte () const |
| USceneComponent * | GetTaggedComponent (FName Tag) const |
| FORCEINLINE bool | GetTriggerIfAmmoLessThanRequired () const |
| FORCEINLINE ETriggerMode | GetTriggerMode () const |
| FORCEINLINE float | GetTriggerRate () const |
| FORCEINLINE float | GetTriggerRateSec () const |
| FORCEINLINE bool | GetUsesAmmo () const |
| FORCEINLINE bool | GetUsesMagazine () const |
| const UWeaponAsset * | GetWeaponAsset () const |
| FWeaponModifications | GetWeaponDefaultModifications () const |
| const FWeaponModifications & | GetWeaponModifications () const |
| FWeaponModifications | GetWeaponModificationsBP () const |
| FORCEINLINE bool | HasAmmo () const |
| FORCEINLINE bool | HasCharacteristics () const |
| bool | HasEnoughAmmoToTrigger () const |
| bool | HasTaggedComponent (FName Tag) const |
| void | Init () |
| void | InitializeWeapon (const struct FWeaponInitializationData &Data, bool bRecallDelegates=false, bool MoveValues=false) |
| FORCEINLINE bool | IsCoolingDown () const |
| FORCEINLINE bool | IsGenerating () const |
| FORCEINLINE bool | IsJammed () const |
| FORCEINLINE bool | IsReloading () const |
| FORCEINLINE bool | IsTriggering () const |
| bool | IsValid () const |
| void | OnUseAmmoUpdated (bool previous, bool current) |
| void | OnUseMagazineUpdated (bool previous, bool current) |
| void | RebuildAsset () |
| void | Reload () |
| void | ReloadLogic () |
| void | ReloadLogicManual (int32 AddAmmo) |
| FORCEINLINE bool | RequiresAmmoToTrigger () const |
| void | SetAmmoSource (UPARAM(Ref) int32 &Source, bool ReturnRemainingAmmo=true) |
| void | SetAmmoSourceFromMap (const TMap< int32, int32 > &Map, const int32 &InKey, bool ReturnRemainingAmmo=true) |
| void | SetAmmoSourceRaw (void *Source, size_t typeSize, bool bSigned, bool bReturnRemaining) |
| void | SetCharacteristics (UWeaponAssetDefaultCharacteristics *NewCharacteristics) |
| void | SetCooldown () |
| void | SetCustomCooldown (float Cooldown) |
| bool | SetSingleModification (FGameplayTag Modification, bool bForceUpdate=true) |
| void | SetWeaponAsset (const UWeaponAsset *NewAsset) |
| void | SetWeaponJammed (bool Jammed) |
| bool | SetWeaponModifications (const FWeaponModifications &newModifications, bool bForceUpdate=true) |
| void | SolveMagazineResize (int32 From, int32 To) |
| virtual void | Trigger (bool isFirst=true) |
| virtual bool | TriggerModeAllowNextTrigger () const |
| void | TryJamWeapon () |
| FORCEINLINE void | UnjamWeapon () |
| void | UpdateMesh () |
Static Public Member Functions | |
| static FORCEINLINE constexpr bool | IsPlaying () |
Public Attributes | |
| TObjectPtr< UWeaponAssetDefaultCharacteristics > | Characteristics |
Protected Attributes | |
| FIntegerPtr | AmmoInMagazine |
| FIntegerPtr | AmmoSource |
| uint8 | bCancelReload:1 = false |
| uint8 | bIsTriggering:1 = false |
| uint8 | bJammed:1 = false |
| uint8 | bReloading:1 = false |
| int32 | BurstIndex = 0 |
| TMap< FName, TSoftObjectPtr< USceneComponent > > | CachedSockets |
| TMap< FName, TSoftObjectPtr< USceneComponent > > | CachedTags |
| uint8 | isGenerating:1 = false |
| FTriggered | OnBeginReload |
| FCooledDown | OnCooledDown |
| FTriggered | OnFinishReload |
| FTriggered | OnJam |
| FTriggered | OnReload |
| FTriggered | OnReloadFailed |
| FTriggered | OnTriggered |
| FTriggered | OnTriggerFailed |
| FTriggered | OnUnJam |
| FBuilded | OnWeaponBuild |
| FTimerHandle | TriggerCooldown |
| FTimerHandle | TriggerTimer |
| TObjectPtr< const UWeaponAsset > | WeaponAsset |
UWeaponComponent handles all weapon mechanics: triggering, reloading, ammo management, jamming, and burst fire.
Key Features:
The component requires a UWeaponAsset and UWeaponAssetDefaultCharacteristics to function. Generated mesh components are automatically updated and attached.
|
protected |
|
overrideprotectedvirtual |
| void UWeaponComponent::BuildAsset | ( | const UWeaponAsset * | Asset | ) |
|
inline |
| bool UWeaponComponent::CanTrigger | ( | ) | const |
|
virtual |
| void UWeaponComponent::Clean | ( | ) |
|
inline |
| UWeaponComponent::DECLARE_FUNCTION | ( | execSetAmmoSource | ) |
| UWeaponComponent::DECLARE_FUNCTION | ( | execSetAmmoSourceFromMap | ) |
|
overrideprotectedvirtual |
|
inline |
| void UWeaponComponent::EnsureHasCharacteristics | ( | ) |
Ensures the weapon has valid characteristics data. If missing, fetches defaults from the current weapon asset.
| void UWeaponComponent::EnterTrigger | ( | ) |
|
inline |
| void UWeaponComponent::ExitTrigger | ( | ) |
| USceneComponent * UWeaponComponent::FindCachedSocket | ( | FName | Socket | ) | const |
| USceneComponent * UWeaponComponent::FindSocket | ( | FName | Socket | ) | const |
| void UWeaponComponent::GenerateInitializationData | ( | FWeaponInitializationData & | Data | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| USceneComponent * UWeaponComponent::GetCachedTaggedComponent | ( | FName | Tag | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| const UWeaponAssetDefaultCharacteristics * UWeaponComponent::GetDefaultCharacteristics | ( | ) | const |
| FWeaponExecutionContext UWeaponComponent::GetExecutionContext | ( | bool | bRefreshNotifications | ) | const |
Generates an execution context for fired projectiles/effects.
| bRefreshNotifications | If true, updates cached socket and tag data before generation |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Calculates unused magazine capacity.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| USceneComponent * UWeaponComponent::GetTaggedComponent | ( | FName | Tag | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprotected |
| FWeaponModifications UWeaponComponent::GetWeaponDefaultModifications | ( | ) | const |
| const FWeaponModifications & UWeaponComponent::GetWeaponModifications | ( | ) | const |
|
inline |
|
inline |
|
inline |
| bool UWeaponComponent::HasEnoughAmmoToTrigger | ( | ) | const |
|
inline |
| void UWeaponComponent::Init | ( | ) |
| void UWeaponComponent::InitializeWeapon | ( | const struct FWeaponInitializationData & | Data, |
| bool | bRecallDelegates = false, | ||
| bool | MoveValues = false ) |
|
inline |
|
inline |
|
inline |
|
inlinestaticconstexpr |
|
inline |
|
inline |
|
inline |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
protected |
|
inlineprotectedvirtual |
|
overrideprotectedvirtual |
| void UWeaponComponent::OnUseAmmoUpdated | ( | bool | previous, |
| bool | current ) |
Reacts to runtime toggle of ammo system. Clears/initializes ammo tracking accordingly. Only works if Characteristics derives from UWeaponAssetDefaultCharacteristics.
| void UWeaponComponent::OnUseMagazineUpdated | ( | bool | previous, |
| bool | current ) |
Reacts to runtime toggle of magazine system. Clears/initializes magazine tracking accordingly. Only works if Characteristics derives from UWeaponAssetDefaultCharacteristics.
| void UWeaponComponent::RebuildAsset | ( | ) |
| void UWeaponComponent::Reload | ( | ) |
| void UWeaponComponent::ReloadLogic | ( | ) |
| void UWeaponComponent::ReloadLogicManual | ( | int32 | AddAmmo | ) |
|
inline |
|
protected |
Initializes ammo system delegate connections and validates ammo/magazine configuration. Called during component lifecycle to ensure ammo tracking operates correctly.
| void UWeaponComponent::SetAmmoSource | ( | UPARAM(Ref) int32 & | Source, |
| bool | ReturnRemainingAmmo = true ) |
| void UWeaponComponent::SetAmmoSourceFromMap | ( | const TMap< int32, int32 > & | Map, |
| const int32 & | InKey, | ||
| bool | ReturnRemainingAmmo = true ) |
Binds a map value as the ammo source. Necessary because containers don't support reference retrieval in Blueprints.
CRITICAL: Map values must be reinterpretable as int64 (e.g., int32, enum, uint8, uint16, not strings or complex types). Other types cause undefined behavior and crashes.
| Map | Source map to read from |
| InKey | Key to find in map; must exist or binding fails |
| ReturnRemainingAmmo | If true, writes unconsumed ammo back to previous source before rebinding |
| void UWeaponComponent::SetAmmoSourceRaw | ( | void * | Source, |
| size_t | typeSize, | ||
| bool | bSigned, | ||
| bool | bReturnRemaining ) |
Low-level ammo source binding. Maps external variable to weapon ammo tracking.
| Source | Pointer to external integer variable to use as ammo source |
| typeSize | Size of the int type (1, 2, 4, 8 bytes) |
| bSigned | Whether the int is signed or unsigned |
| bReturnRemaining | If true, remaining ammo is written back to the previous source |
|
inline |
| void UWeaponComponent::SetCooldown | ( | ) |
| void UWeaponComponent::SetCustomCooldown | ( | float | Cooldown | ) |
| bool UWeaponComponent::SetSingleModification | ( | FGameplayTag | Modification, |
| bool | bForceUpdate = true ) |
Updates a modificator in a specific slot. Must be overriden in order to work add features.
| Slot | The slot where the modification is applied. |
| Modification | The modification to apply. |
| bForceUpdate | Forces to update all generation even if no changes were made |
| void UWeaponComponent::SetWeaponAsset | ( | const UWeaponAsset * | NewAsset | ) |
| void UWeaponComponent::SetWeaponJammed | ( | bool | Jammed | ) |
| bool UWeaponComponent::SetWeaponModifications | ( | const FWeaponModifications & | newModifications, |
| bool | bForceUpdate = true ) |
Updates all modification to match the input.
| newModifications | Map containing the new mods and slots. |
| bForceUpdate | Forces to update all generation even if no changes were made |
| void UWeaponComponent::SolveMagazineResize | ( | int32 | From, |
| int32 | To ) |
Adapts weapon behavior when magazine size changes at runtime. Adjusts ammo counts to stay within new capacity limits. Only works if Characteristics derives from UWeaponAssetDefaultCharacteristics.
|
virtual |
|
virtual |
Validates if the current firing mode permits another trigger based on burst state. For single/auto modes: always true. For burst: true if burst index hasn't reached max.
| void UWeaponComponent::TryJamWeapon | ( | ) |
|
inline |
| void UWeaponComponent::UpdateMesh | ( | ) |
|
protected |
Reference to magazine ammo storage when UsesMagazine is enabled. Tracks rounds currently loaded in the magazine, separate from source ammo.
|
protected |
Reference to external ammo storage (belt-fed, backpack, etc.). Must be bound via SetAmmoSource() or SetAmmoSourceRaw(). Do not rebind accidentally—consumption updates write back to the original source.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Index for burst fire mode.
|
mutableprotected |
|
mutableprotected |
| TObjectPtr<UWeaponAssetDefaultCharacteristics> UWeaponComponent::Characteristics |
|
protected |
|
protected |
Delegate for when the weapon begins reloading.
|
protected |
Delegate for when the weapon has cooled down.
|
protected |
Delegate for when the weapon finishes reloading.
|
protected |
Delegate for when the weapon jams.
|
protected |
Delegate for when the weapon is reloading.
|
protected |
Delegate for when the weapon reload fails.
|
protected |
Delegate for when the weapon is triggered.
|
protected |
Delegate for when the weapon trigger fails.
|
protected |
Delegate for when the weapon unjam.
|
protected |
|
protected |
Tracks trigger rate cooldown between shots. When active, IsTriggering() returns false and shots are blocked.
|
protected |
For custom trigger timing—delays between pull and projectile spawn. Only used if CustomTriggerExecutionTiming is enabled in characteristics.
|
protected |
The weapon asset associated with this component.