What are equipment handlers?
As the name suggests we use equipment handlers to handle all things related to our equipped equipment. This includes the visual shown on our pawn, as well as any added functionality the equipment may provide. Equipment handlers are added to the pawn automatically when items are equipped, and they are removed when they are unequipped.
We assign our equipment handler to our equipment in our DT_Equipment data table.
The Base Equipment Handler
By default, all equipment either uses, or is based off of, the AC_EquipmentHandler component in the Blueprints/EquipmentHandlers/ folder. This base equipment handler is responsible for the visual state of our equipment. We then inherit from this blueprint to add in our extra functionality, like how our weapons work, or how the rocket backpack launches the player in the air when jumping.
You can use the base handler for any equipment that is just showing a static or skeletal mesh on the pawn. Or, build off of it and treat it as the foundation layer. To make your own custom handler you will make a child of either the base handler, or one of the other provided ones. Then to add in your custom logic you override specific functions integrated into the lifecycle hooks of the base handler.
If you make your own handler, you can override which is associated with a piece of equipment in the DT_Equipment data table.
AC_EquipmentHandler Overrides
AC_EquipmentHandler Important Events
AC_EquipmentHandler Variables
Simple Logic Handler
The simple logic handler extends our base equipment handler to add an additional input mapping context, it also manages the input actions related to this input mapping context and provides additional events for us to override for both the up and down state of a primary and secondary input action. These events allow us to take advantage of press, release, and hold actions. This IMC_InventorySystemDemo_SimpleHandler input mapping context in the Blueprints/EquipmentHandlers/Weapons/Simple/ folder is added using the onSeutpClient override.
The simple handler is an abstract class, which means you can’t use it directly but instead need to make a child of it and use that instead.
Simple Logic Handler Overrides
Simple Logic Handler Added Methods
Simple Logic Handler Variables
Muzzle is not found on your mesh component a forward vector from the player is used for the spawning location of projectiles. The value of this integer is the distance (default: 500) from the player.Simple Logic Extended Handlers
We extend the functionality of our Simple Logic Handler to create the following:
Simple Range Handler
AC_EquipmentHandler_Simple_Range in the Blueprints/EquipmentHandlers/Weapons/Range/ folder is a simple range weapon that shoots a projectile and consumes an ammo item. It uses a custom UI that shows the current and remaining ammo count, and also includes a custom input action for reloading. Both of these assets can be found in the same folder as the simple range equipment handler.
This handler uses the primary action to shoot the weapon, and if the clip is empty, reload it. It uses the right click to tell the pawn it is aiming. The change to the camera occurs inside our pawn when the EquipmentAction event on our event graph receives the Aim Start or Aim Stop actions.
These first few ammo related variables are dynamically set at runtime when the setupAmmo function is called in this handler. It sets the values of these variables based on data pulled from the dynamic data of the equipment item. To set these variables you would set the associated keys in the item’s dynamic data.
ammo) - Our ammo item row name.ammo.clipmax) - The max number of ammo per ammo clip. Once spent reloading required.ammo.clip) - The current number of ammo shots left in the ammo clip, updated automatically each shot. If you manually set this dynamic data key the value will be used as the starting ammo already loaded in the clip when the weapon is first picked up. If this value is not found the range weapon will proceed as if the clip is empty, thus needing to be reloaded. Then, once the ammo is loaded this key will be added.These variables can be set manually in the handler:
Simple Range Automatic Handler - AC_EquipmentHandler_Simple_RangeAutomatic
This handler extends our Simple Range Handler to make the weapon an automatic, allowing us to hold down the primary action to continue firing at a rate defined by the AutomaticRateOfFire variable inside the handler.
Simple Range Automatic Handler (with Extras) - AC_EquipmentHandler_Simple_RangeAutomatic_Extra
This handler extends our automatic range handler by integrating a line trace (lineTraceShoot), and disables the actual projectile. Also offers a way to define the max distance of the line trace using the dynamic data key range. You can also set variables to define a minimum damage (shotMinimumDamage), and shot chance (shotChance). We use this handler for our Pistol and Rifle Lyra clone examples. The customized data for different equipment is driven through dynamic data.
Simple Throwable - AC_EquipmentHandler_Simple_Throw
This handler is an extension of the Simple Handler, and illustrates a way to handle throwables, like grenades. The player charges up a throw by holding down the primary button, then when they release the projectile is hurled.
The distance thrown is based on the hold time, more specifically a percentage based on the amount of time held against the max hold time. You can define the max hold duration, the throw forward and height velocity. If you hold the button for the max duration the full velocity will be used. If you hold the button for less then the max the percentage will be used to determine the velocity.
These variables are available on this handler:
This additional override is added through this handler:
Additional Sample Handlers
How to handle Unarmed Attacks
Something like this is a bit out of scope for this asset, and would be better aligned with a combat system. I still want to at least point you down the right path if you are looking to provide a simple functionality and don't mind creating the code yourself. Here is what I suggest:
- Create your own input bindings or actions for the primary and secondary attack and place the events somewhere like in your pawn.
- When your input events are hit, check to see if the Equipment Stance saved in your pawn is set to your default, which we set as
Unarmedby default. This default can be changed on the AC_InventorySystem component we added to our player controller. Browse to the Configuration Equipment section in the details panel of this component and the variable you are looking for is EquipmentDefaultStance. - Only when it is set to
Unarmedwill you be safe to proceed with your unarmed attack montages and logic.
The most important part about this is checking to make sure the equipment stance is Unarmed.
You wouldn't use an equipment handler for something like this, and it wouldn't be part of the equipment system. Instead you would write your own code to handle it, most likely in the pawn or a component on the pawn. You can still use the equip and animation events on the pawn if you would like, you would just have to call them manually.