top of page
Search

Modular Weapon System (UE5|C++|Blueprints)

About Demo

  • Made in over 2.5 weeks

  • This is a mini project(part of bigger project) that implements flexible modular weapon system that can be used in any project.

  • Implemented a modular weapon system using Data Assets, supporting reloads, fire modes, hitscan/projectile logic, weapon switching, and UI feedback like crosshairs and hit markers.

  • Unreal Engine 5 C++



Code-Design Breakdown


  • Design Principles and Patterns Used

    • Data-Driven Design with Data Assets: Each weapon is defined via UWeaponDataAsset, which contains a FWeaponStructure. Designers can tweak behavior (damage, fire rate, effects) in the editor without touching code.

    • Modular Weapon Logic: Weapon behavior (hitscan, projectile, reload) is encapsulated inside the APWeapon class and accessed via a unified interface.

    • Enum-Based Switching: Weapons are switched and attached via an enum system (EWeaponTypes), simplifying selection and modularity.

    • Separation of Concerns: Visual effects (VFX, camera shake) are handled separately from logic (fire, reload, ammo), making the system cleaner and extendable.


  • Multiplayer-Ready Weapon System

    What I did:

    I built the entire weapon system to support networked multiplayer by:

    • Replicating weapon actors (SetReplicates(true) in APWeapon).

    • Using OnRep, Server, and Multicast RPCs where necessary.

    • Ensuring fire, reload, and effects are correctly shown to all players.

    • Replicating variables like CurrentWeapon using DOREPLIFETIME() in APCharacter.

void APCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(APCharacter, CurrentWeapon); }
  • Why:

    Multiplayer games need authoritative logic on the server, with effects synced across all clients. This ensures fair, responsive gameplay.

    • Firing logic only runs on the server, but visual/audio feedback like VFX, sounds, and recoil is replicated using multicast events or client predictions.

    • I used APlayerController::ClientStartCameraShake() to shake only the local player’s camera.


  • Data-Driven Weapon Definitions

    What I did:

    Defined all weapon stats and visuals inside a FWeaponStructure, stored in a UWeaponDataAsset.





 
 
 

Comments


 © 2025 Rahul Chandra 

bottom of page