🚀 Spring Sale is live! 🚀 Don't miss your chance to get all my products at 30% OFF!  

Get it!

Bullet System

Overview

The Bullet System is part of the GCS, designed to support ranged combat, spells, and projectiles.

As a heavy player of Elden Ring, I want my bullet system to be as excellent as that of Elden Ring. To achieve this, I have studied extensively how spells work in Elden Ring and implemented similar mechanics in Unreal Engine. You can see how impressive Elden Ring's bullet system is, and my version will continue to improve: Elden Ring Bullet System.

In GCS, you can quickly add various types of bullets to achieve different game mechanics.

Bullet Definition

In real projects, you might define thousands of bullets. Therefore, bullets are managed through a DataTable, and all object references use soft object references, so you don’t need to worry about my code causing your project to explode.

You manage and edit all bullets in your project by creating a DataTable asset with the structure type GCS_BulletDefinition.

子弹系统.001

Each row represents a bullet definition, and within each definition, you can configure many parameters. The most important parameters are as follows (other parameters are commented and will not be elaborated on here):

  • BulletActorClass: Specifies the bullet ActorClass corresponding to this bullet definition. You can choose from the defaults or define a special bullet instance for specific bullets.
  • BulletCount: This controls how many bullet instances will be generated when using this definition. Combined with the launch configuration (LaunchConfiguration), you can create many interesting bullet effects.
  • AttackDefinition: Use this option to select different attack definitions. Upon hitting a target, the bullet will apply game effects to the target based on the information specified in the attack definition.

Bullet Instances

GCS provides a C++ class GCS_BulletInstance as the parent class for all types of bullet instances, C++ version handles performance-sensitive logic while also providing a premade Blueprint subclass (BP_GCS_Projectile) which you can directly use.

The default implementation is general enough that you typically won’t need to create new Blueprint subclasses.

Triggering Bullets via Animation

Please refer to: Combat(Attack/Defense) System

Triggering Bullets via Blueprints

At the system's core, the GCS Bullet Subsystem is provided, allowing you to:

子弹系统.002

GCS's Bullet Actor also implements the GCS_EffectCauser interface, meaning you can set up pre-created game effect instances for the bullet before it is fired. When the bullet hits a target, the passed game effect instance will be applied.

子弹系统.003

The AttackRequest is a default instantiated object. Therefore, when you create a variable of type AttackRequest in any Blueprint, you create an instance of AttackRequest, not referencing an already existing AttackRequest object. The instantiated request will be saved with the Blueprint it resides in.

Bullet Object Pool

All created bullet instances are managed through an object pool. In simple terms, once a bullet completes its purpose, it will be disabled and cached. When a new bullet needs to be created, the system will first look for an available bullet from the cached ones and reactivate it. This significantly alleviates the performance costs associated with frequently creating and destroying bullet actors.

Therefore, when customizing your bullet actor, you need to be aware that:

  • The BeginPlay and EndPlay of the bullet instance are usually called only once, but OnBulletBeginPlay and OnBulletEndPlay can be called repeatedly.
子弹系统.004

Bullet Client Prediction

GCS also supports client prediction, meaning that in high-latency network environments, you can pre-generate bullets locally. The client-predicted bullets will merge with the server versions.

This feature is still WIP, and more documentation will be provided once it is stable.