This project contains the C++ source code for a First Person Shooter demo in Unreal Engine 5.
- Source/MyFPSGame: Contains the C++ classes.
MyFPSCharacter: Player character with Health, Shooting (Server RPC), and Damage handling.FPSEnemyCharacter: Enemy character with AI support, Health, and Attack logic.FPSEnemyController: AI Controller that chases the nearest player.MyFPSGameMode: Manages game rules, scoring, and win conditions.MyFPSProjectile: Projectile logic.
Since this is a C++ project, you need to compile it.
- Generate Project Files:
- Right-click
MyFPSGame.uprojectand select Generate Visual Studio project files.
- Right-click
- Compile:
- Open the generated
.slnfile in Visual Studio. - Build the solution (Development Editor configuration).
- Open the generated
- Open Unreal Engine:
- Open
MyFPSGame.uproject.
- Open
To use the C++ classes, you should create Blueprints that inherit from them:
-
Game Mode:
- Create a Blueprint class inheriting from
MyFPSGameMode(e.g.,BP_MyGameMode). - Set
ScoreToWinin the Details panel (default is 5). - Assign
BP_MyGameModeas the default GameMode in Project Settings -> Maps & Modes.
- Create a Blueprint class inheriting from
-
Player Character:
- Create a Blueprint inheriting from
MyFPSCharacter(e.g.,BP_Player). - Add a Skeletal Mesh (Arms) to the
Mesh1Pcomponent. - Set up the Enhanced Input actions in the Event Graph (Assign Mapping Context).
- Set
BP_Playeras the Default Pawn Class in your GameMode.
- Create a Blueprint inheriting from
-
Enemy Character:
- Create a Blueprint inheriting from
FPSEnemyCharacter(e.g.,BP_Enemy). - Add a Skeletal Mesh (e.g., Mannequin).
- Place
BP_Enemyinstances in the level.
- Create a Blueprint inheriting from
- Combat: Players can shoot enemies. Enemies chase and attack players.
- Health System: Both players and enemies have health. Replicated over network.
- Scoring: Killing an enemy grants 1 point. Reaching the target score wins the game (Restarts).
- Multiplayer: Supports network replication. Test by setting "Number of Players" to 2 and Net Mode to "Play as Listen Server".