Author a Ranged Attack
This page builds the smallest ranged shot: one bullet definition, one bullet request, and an ability that calls WaitForBulletEvent, reads UGCS_AttackRequest_Bullet from OptionalObject, and hands it to the bullet component. Predicted bullets own trajectory and presentation only. Gameplay Effects, chain bullets, and emitter follow-ups happen on the server.
Related pages: if the Flow still has no Result, start with Register the First Attack Result. The bullet contract is in Bullet Runtime; request fields are in Attack Definitions and Requests.
Prerequisites
- You attached Combat and Bullet components from Attach Combat Components. Hit detection also needs the Trace component. The target Flow already registers a Result from the attribute callback, as in Register the First Attack Result.
- The authority already called
InitializeAbilitySystem. - You have one
FGCS_AttackDefinitionrow whoseTargetEffectClasschanges a target attribute. - You have a bullet actor that implements
IGCS_BulletInterface. InheritingAGCS_BulletInstanceorAGCS_SphereBulletInstanceis enough.
1. Author the bullet definition
Create a Data Table with row type GCS Bullet Definition (FGCS_BulletDefinition):
Field | This page |
|---|---|
| A spawnable class that implements |
| One shot, angle 0 |
| For example 1500, enough to see a trail |
| The existing attack-definition row |
| At least one hit Trace; these override traces on the bullet instance class |
Count, spread, and speed live on the definition, not the request. Leave chain and emitter empty on this page; those spawn on the server only.
2. Fill the bullet request
Create UGCS_AttackRequest_Bullet:
Field | Role |
|---|---|
| The bullet-definition row from step 1 |
| Aim origin: |
| Needed except for camera-towards-focus; a missing socket falls back to the source location |
| Turn on when a locked target is required to fire |
PawnForward or CameraTowardsFocus is enough here. Custom must override GetTargetingTransform. A weapon origin can also use GCS_GetTargetingStartTransform on the weapon interface.
3. Hand the request to the Task through an Event
In the ranged ability, call WaitForBulletEvent:
- Set the Gameplay Event tag to listen for.
bInUseScopedPredictionWindowdefaults to true and wraps a local player shot inFScopedPredictionWindow.- When the event fires, the Task reads
UGCS_AttackRequest_BulletfromEventData.OptionalObjectand passes it toUGCS_BulletSystemComponent. - Success broadcasts
OnBulletSpawned; failure broadcastsOnBulletSpawnFailed.
You can store the same request on GCS_ANS_BulletTrace and fire a Gameplay Event with that OptionalObject from the window. The notify is not a runtime launcher either.
ValidateAttackRequest is overridable. The default only checks that the request is valid and BulletDefinitionHandle resolves a row. Fire rate, ammo, and resource legality stay with the project. Do not assume the component rejects those shots.
Expected result
After a locally controlled player fires, the client shows a trail immediately and the Debugger Bullet section lists a predicted Entry. After the server confirms, the Entry is confirmed and a hit applies GE. The predicted client bullet does not change attributes.
Verify
- Open the Combat category of Gameplay Debugger and inspect Bullet after one shot: entries, instances, and Pending / Confirmed / LocalPredicted counts.
- The predicted bullet has a trail and FX; target attributes do not change.
- The server window shows the same Entry and an Attack Result after the hit.
- If you configured chain or emitter, follow-up bullets appear only on the server. The client does not spawn its own batch.
- Set
LogGCS_Bulletto Verbose to see spawn, confirm, or deny.
Common failures
Symptom | Check first |
|---|---|
Event arrives, nothing spawns | |
Trail, no GE | Confirm it is a predicted bullet. No GE on predicted bullets is the contract |
Server has no Entry either | The owning client reached server spawn; AI / non-locally-controlled shots spawn authoritatively |
| The class implements |
Aim is wrong | |
Fire rate is unlimited | The default does not check rate or resources. Gate in an overridden |
Next
After the ranged loop works, continue with Configure Combo and Weapon. Prediction that disagrees with authority: Debugging and Troubleshooting.