SWeaponPickup class overview - whoisEllie/Project-Isolation GitHub Wiki

SWeaponPickup

Overview

SWeaponPickup integrates with isolation-game's attachment and weapon systems to provide a straightforward means of creating weapon pickups. It pulls from the same data table as SWeaponBase and is built to handle all possible pickup situations for a 2-weapon setup.


Variables

  • TSubclassOf<ASWeaponBase> WeaponReference; - The reference to the weapon which should be spawned on pickup

  • FWeaponDataStruct DataStruct; - A reference to the weapon data struct which should be edited

  • UDataTable* WeaponDataTable; - A reference to the weapon data table, which helps us check if the weapon has attachments or not

  • UDataTable* AttachmentsDataTable; - A reference to the attachment data table from which we pull attachment meshes and other data

  • bool bRuntimeSpawned; - If this weapon pickup is being spawned at runtime. This is passed through from the player character, and determines whether or not we update the locally stored ammunition variables in DataStruct. If the weapon is spawned from the beginning of the play session as a pickup, then we reset its ammunition values and health to their defaults.

  • bool bStatic; - Whether physics should be simulated on this weapon, or whether it should remain static as a pickup. If a pickup is static and it is replaced by another weapon, that weapon will also be static and take its position.

  • TArray<FName> AttachmentArray; - The array of attachments to spawn, derived either from the actor spawning the pickup or set by instance in the editor.

  • bool bIsNewPrimary; - Will the weapon take the position of a primary weapon or of a secondary one.

  • FText WeaponName; - The name of the weapon used for the pickup UI.

  • UStaticMeshComponent* MainMesh;, UStaticMeshComponent* BarrelAttachment;, UStaticMeshComponent* MagazineAttachment;, UStaticMeshComponent* SightsAttachment;, UStaticMeshComponent* StockAttachment;, UStaticMeshComponent* GripAttachment; - The mesh components for the various types of attachment present in the game as well as the base (or root) mesh for the weapon.


Functions

  • virtual void Interact() override; - An override for the Interact() function found within SInteractInterface. Within it we implement all the pickup logic required for this class.

  • void SpawnAttachmentMesh(); - A blueprint callable function that spawns the meshes for the weapon attachments. This function is blueprint implementable in order to satisfy the needs of custom weapon spawners (such as the weapon dispenser in the Project Isolation alpha).


Uses

Naturally a weapon pickup is a relatively useful item. This class gives you a solid foundation to start building weapon pickups, and integrates well with both SWeaponBase and SCharacter. To use it, simply create a child for each weapon base class and fill in the relevant variables. If you would like weapons to drop pickups when unequipped (which you probably do haha), you can also set PickupReference to be your pickup class.

⚠️ **GitHub.com Fallback** ⚠️