Character Setup
Enabling The Pawn To Shoot
There are two main components that need to be set up before you are able to shoot a target: GSShootingComponent and GSRollbackComponent. The GSShootingComponent should be added to the player pawn and controls everything related to the weapons and the shooting. By default the equipment loadout will be empty but we will go through the process of creating and equipping a new weapon in the next section.
The pawn must also inherit from the GSShootingInterface which both allows us to get access to the shooting component when required and also allows us to set the pawn as the input producer for the shooting component. By overriding ProduceShootingInput and setting the InputProducer variable, we can send inputs from the player to the shooting component and control the simulation. Below is a very simple example of how to implement this but feel free to customize it to whatever works in your own project.
The final step to set up the shooting component is to tag the component that you want the weapon mesh to attach to. In Project Settings->Gunsmith Settings there is a “Weapon Attach Component Tag” variable which should display GunsmithWeapon by default. Copy this text into the Tags->Component Tags array on your pawns mesh.
Setting Up The Pawn To Be Hit
The second component is the GSRollbackComponent and should be added to any actor that needs a primitive component to be recorded and used when rolling state back for hit validation. The pawn should also inherit from the GSRollbackInterface for easy rollback component access.
On BeginPlay the GSRollbackComponent will spawn a GSRollbackProxy which is an actor with identical primitive setup to the owning actors collision but set up with the collision profiles that we created in the previous step. This is the actor that the projectiles will hit and it means that when we roll back history for hit validation, we can avoid moving the actual character and potentially writing over any state.
Initializing The Rollback Proxy
In this example, the primitive setup exists in the pawn’s skeleton asset so we can use SetupSkeletalMeshRenderer which will extract that and reproduce the collision setup as basic shapes. RollbackBones is a list of bones that we would like to create the primitive for and the collision profile and object names must match the ProjectileTarget collision preset that we set up in the previous section. Once set up, change the collision profile of the SkeletalMeshComponent so that we no longer hit it with projectiles.
Dealing Damage
The previous two components should be enough to get started with shooting and hitting targets but there is a third component that most games will probably require at some point - GSHealthComponent. This component stores the health state of the owner which will be reduced when hit by a projectile. This is also accompanied with a GSDamageTargetInterface which the pawn must inherit from. Once added, the rest of the simulation should apply the damage automatically but feel free to bind to a couple of the events that are provided such as OnDamageTaken and OnDeath.