Fps Multiplayer Template Documentation
Fps Multiplayer Template Documentation
DOCUMENTATION
BLUEPRINT COMPONENTS
First we will see the blueprints components that come with the project, because the main
blueprints in the project will make use of them.
AC_Team
This component is used on the player state “BP_PlayerState” and handles the team with an
integer, this variable is replicated and uses an “OnRep” function that triggers a dispatcher
“OnTeamChanged”.
AC_Loadout
In the Loadout Component we will store the weapons that the player will use on spawn,
lethal equipment, player class and perk. This component can be extended to add player
skins, weapon attachments, etc.
The component will be attached to the player controller, since we need to have access to it
even without a controlled pawn. The AI won't use this component, we can just generate the
loadout randomly.
AC_InteractSystem
This component will use a line trace every 0.1 seconds in front of the player to check for
interactables, if the line trace collides with an actor with the “I Interactive” interface the player
will be able to interact with that actor, we can set the description and the interact time of that
actor thanks to the functions that come with the interface.
The component will create a widget automatically to show the item description and the key
needed to interact with that actor.
To create a new interactable actor, just create a new actor, add the “I Interactive” interface
and set the Interact time and the description of the actor.
AC_InventorySystem
This component saves references to the current equipped weapons and lethal equipment
and also the ammunition. The component will be attached to the “BP_PlayerCharacter”
which is the default player pawn.
Important Functions
CreateAndEquipLoadout
Equips the primary weapon, secondary weapon and lethal equipment then sets the
“PrimaryWeapon” as the “CurrentWeapon”
Equip weapon
Creates the weapon Actor, sets the owner and attaches the weapon to the FPP mesh and
the TPP mesh.
GetCurrentWeapon
To get access to the current weapon.
DestroyWeapons
Destroys all the weapons on end play, when the player is kicked or leaves the game.
AC_BotManager
Handles the spawning of the bots and this component should be added to the game state, in
our case “BS_Base_GS”, it is important to set the behaviour tree that the bots will use for
each game mode, but we will cover this later in the “BP_Base_GS” section.
AC_ChatSystem
This component is added to the player controller blueprint “BP_BasePlayerController” and
handles the chat, creates the widget and the server will send the messages to every
controller that uses this component. Make sure that it is added to the player controller to be
able to access it even without a pawn and at the same time we avoid having the component
on the AI players.
AC_ControllerSettings
The controller settings component is heavily related to the player settings, everything the
player can choose on the settings menu that is not saved in the default player settings
(resolution, vsync, texture quality, etc) will be saved here.
Variables
● bUseTPP
● bY_AxisInverted
● bX_AxisInverted
● bShowFps
● UIVolume
● MusicVolume
● MouseSensitivity
● AimSensitivity
● bShowLatency
Event Dispatcher PerspectiveChanged
Will be called if the player changes from TPP to FPP or the other way around so you can run
some code if the player changes the perspective but I recommend to use FPP or TPP only
to make the code easier to handle.
AC_KillFeed
Very similar to the chat component but this time the server will create a kill feed message to
all the players controllers that use this component, the widget for those messages will be
created automatically in the beginplay event. The AI Controller needs to have this
component to work.
AC_Killstreak
This component is used to store the current kill streak of the player and unlock different
abilities like calling a UAV to see the enemies in the minimap.
AC_MatchSettings
In this component we will save the settings that the player can select in the “create game”
widget and other variables that will be hidden for the player that we can set when we are
creating the game mode, like for example “bAllowRespawn” that can be used in game
modes that don't allow the player to respawn and will only be able to do it after the end of the
round or in the next game, like in a battle royale game mode.
Variables
● BotsTeamA
● BotsTeamB
● AIDificulty
● FriendlyFireDamageMultiplier
● PointsToWin
● RoundsToWin
● Pre match time
● Post Round Time
● RoundTimeLimit
● Game Mode Name
● bMatchWithTimeLimit
● bAllowBots
● bAllowRespawn
● bAllowFriendlyFire
● bAllowChangeTeam
AC_MatchStateSystem
By default in Unreal engine the game has 3 states, Waiting To Start, In Progress and Waiting
Post Match but doesn't have anything to handle the state of a round based match, we are
going to use an enumeration for that called E_RoundState with 3 states also, Waiting to Start
Round, Round In Progress and post Round. This component handles the transition between
these states and notifies the rest of the players in case they have to run some code.
MatchStateSytem component also handles the match timer and team scores.
When we create a new game the game state goes from Waiting To Start to in progress as
well as the round state to Round In progress, when the rounds end it goes to Post Round
and resets the level, in case it is the last round we also set the game state to Waiting Post
Match.
AC_PawnInfo
Pawn info holds information about the pawn useful for other players to know to be able to
play the correct animation and also uses a few event dispatchers to play some code when
the player changes these variables.
● bRunning
● bAimign
● bShooting
● bUsingLethal
● bCrouching
● Leaning
EventDispatchers
● OnStartAiming
● OnStopAiming
● OnStartShooting
● OnStopShooting
● OnStartRunning
● OnStopRunning
● OnStartUsingLethal
● OnStopUsingLethal
● OnStartCrouching
● OnStopCrouching
● OnDamageDone
AC_PlayerScores
Used to create the PlayerScores widget and also handles the input to show it and hide it.
The component is added to the player state blueprint to ensure that the player can see the
scores even if the controller pawn is dead.
AC_PlayerStateInfo
The Player State Info component stores variables that will be used on the player scores. The
functions on this component are only setters and getters for the variables,
GetRandomBotName to assign a name for the bots at the beginning of the game and
OnRep functions for Kills, Assists, Deaths and PlayerScore.
● Kills
● Assists
● Deaths
● PlayerName
● PlayerScore
AC_SpawnSystem
The spawn System Component will save all the spawns on the map at the beginning of the
game and will handle the spawning of the players, this component is also responsible for
choosing the best spawn point for each player, trying to avoid other characters near the
spawn point. Keep in mind that this component uses the Team Component so if you are not
planning to use it, replace the way the team is handled to make it work.
EventDispatcher OnPlayerSpawned
Used for the minimap to create a new marker for the new player spawned.
AC_UI_Manager
This component is used to create widgets for the player and hold references to it when
needed.
MAIN CLASSES
BP_PlayerCharacter
This blueprint inherits from ACharacter and is used by the players and the AI. The blueprints
is divided by 5 graphs, the EventGraph is used for the “Tick” event and the “BeginPlay”,
Health&DeathGraph to handle damage and dead events, ActionGraph for the player inputs
and actions(running,jumping,etc),FireWeaponGraph, for the fire weapon input and lastly the
ClassAbilitesGraph where we can find the code for the different abilities that the player can
use.
Components
● PawnInfo
● InventorySystem
● InteractSystem
● HealthComponent
Replicated Sprint
The replication sprint is a custom solution to make the sprint work on multiplayer with
blueprints using the movement prediction system of the movement component, to do this we
just set the “MaxWalkSpeed in the movement component to the speed that we will have
while the player is sprinting then we use multipliers to set the walk, crouch and aim velocity,
so for example walk speed can be 0.625 of the max speed. (MaxSpeed = Sprinting Speed =
MaxWalkSpeed this is just name of the variable in the “character movement component” but
can be confusing)
If you want to change the max speed, you will have to use the “MaxWalkSpeed” variable and
then adjust the multipliers to your liking in the Calculate Movement Input function.
BP_PlayerState
In the player state blueprint we handle the player scores and the player team for that we use
2 components, PlayerStateInfo to hold the player kills, deaths, assists and every other
statistic that you want to store there like accuracy or fired shots for example and
TeamComponent for the team of that player.
Components
● PlayerStateInfo
● TeamComponent
BP_PlayerController
The player controller will hold all persistent information that the pawn will use and some input
handling for certain widgets that don’t need the pawn to be alive to be shown, like the score,
the chat, etc.
If we want to hold information about skills to use, perks, or weapons to equip on spawn this
is going to be the place, in the template that information goes in the loadout component and
can be extended to add attachments for the weapons or character skins if necessary.
Components
● Loadout
● ControllerSettings
● KillFeed
● ChatSystem
● PlayerScores
● UI Manager
BP_Base_GM
The game mode only runs on the server and the clients don't have access to it,
BP_Base_GM will set the initial team to every new player and send a server message to all
the player chat every time a player joins or leaves the game or when the state of the match
changes from” Waiting to Start” to “InProgress” and then to “WaitingPostMatch”.
BP_Base_GS
The base game state blueprint will have some functions to handle the beginning of the game
and what to do after a “reset” event after the end of a round. This blueprint will use 4
components to handle the spawn of the players and bots and the state of the current match,
unlike the game mode blueprint everyone can access this blueprint not only the server.
Components
We need to set the values of all the variables mentioned for each game mode.
SpawnSystem
No need to set any variable.
MatchStateSystem
No need to set any variable.
BotManager
● AI Behavior Tree
MatchSettings
● Allow Respawn
● FriendlyFireDamageMultiplier
● AllowBots
● PointsToWin
● RoundsToWin
● AllowChangeTeam
● Pre match time
● Post Round Time
● RoundTimeLimit
● Game Mode Name
BP_BaseWeapon
The main blueprint for all weapons is “BP_BaseWeapon” and all weapons should inherit
from this class, even melee weapons, and it will store all the montages for first person and
third person, the rest of the animations will be included in the animation layer for that
weapon. There are lots of variables that can be set in the base weapon blueprint that allows
you to create different weapons from a shotgun to a sniper rifle, changing a few parameters.
Important Variables
● AmmoPerMag
● ActualAmmo- used to save the ammo in case someone picks the weapon from the
floor.
● Damage
● Fire rate
● WeaponName
● WeaponRange
● WeaponSpread
● WeaponVerticalRecoilMax
● WeaponVerticalRecoilMin
● WeaponHorizontalRecoilMax
● WeaponHorizontalRecoilMin
● AmmoType
● Bullets Per Burst - only for weapons that have burst mode
● Bullet Velocity
● Firing Modes (list of firing modes of that weapon, can be auto, semi and or burst)
● Actual Firing Mode (The weapon will start with this mode)
● AimingFOV - used to know how close the FOV gets while aiming, 90 is the default
FOV of the camera.
● Weapon type, used to determine the animations to play on the animation blueprint
● HasSuprresor - to appear in the compast or not after shooting
Weapon Transform / Offset
Instead of having a socket for each weapon the template uses a method that doesn’t require
any socket instead we attach every weapon to the “hand_r” bone and then we add an offset
in the begin play of the weapon, this offset can be set in the variables “FPP Weapon Offset
Transform” and “TPP Weapon Offset Transform” for first person and third person
respectively, to know the offset you can either get that ___location from the program that you are
using to make the animations or you can create a preview socket on the skeleton and add a
preview asse, in this case the new weapon, and position it by hand, this method won’t fit
perfectly so it’s always recommended to create custom animations for custom weapons.
Damage Type
The weapon damage type will transfer the information from the bullet to the victim, that way
we can use it to show the weapon in the Kill feed.
The weapon damage type will transfer the information from the bullet to the victim, that way
we can use it to show the weapon in the Kill feed.
To use one mode or the other there is a boolean called HitScan Bullets, in the default version
of the template the shotgun will always use Hitscan bullets due to the limited range of the
weapon and for optimization purposes.
Firing Modes & Actual Firing mode
In the array Firing modes you can add the firing modes that weapon is able to do
BP_Player_Spawn
The name of this blueprint is “BP_PlayerSpawn” and inherit from “Player Start”, the main
purpose of creating a custom spawn is to allow to set the team of the spawn and to control if
it's active or not from the start, later you can activate the spawn with blueprint code.
To work in any game other than “Rush” set the team to the team that will be using this
spawn, leave the boolean active to true, the phase variable only will work in rush, the spawn
can be used in the phase “0” of the match if the phase is 0, in the phase 1 if the phase is 1
and so on.
Spawn Protected Zone
This is an optional feature to protect the spawn zones and avoid spawn killing, to use it drop
it on the map, set the correct values to cover all the spawn and set the team that will be
using the spawn zone without a warning.
Any other team will get a warning if they enter the trigger box and will die if they don’t leave
in a few seconds.
BP_GameInstance
BP_GameInstance inherits from the Game Instance class and it is used to save the settings
for the match. Those settings are modified in the “WB_CreateMatchMenu” widget.
Enhanced Inputs
The template uses the new enhanced input system to handle the inputs, all the default inputs
that come with the template are in the Inputs folder, to create a new one just create the
InputAction first and then add it to an Input Context (remember to add it also to the
“IMC_PawnInputs_Default” so you can restore the default keybinds in the settings menu),
there are currently 3 InputContext “IMC_PawnInputs” to handle the pawn inputs,
“IMC_ControllerInputs” for the controller (scores, chat, settings,etc) and
“IMC_SpectatorInputs” for the spectator. Don't forget to use the “Add Mapping Context” node
if you want to add a custom Mapping Context.
ANIMATIONS
In the “How to “ section I will describe how to add animations for a new weapon.
GAME MODES
Conquest
Secure the Conquest capture points “BP_ConquestCapturePoint” to get points per tick, this
tick can be changed inside the capture point blueprint, the default tick will be 1 second, the
more objectives your team controls the more points you will get per tick, the first one getting
to the required amount will win the game.
To create a map for Conquest, place the player spawn for each team and add 3 capture
points to the map, remember to set the letter of the objective and the icon to display, more
points can be added or removed doing some minor modifications to the HUD and game
mode if needed.
Search & Destroy
In this game mode each player has only one life, if they die they will have to wait until the
next round to play. The objective is to get the bomb and plant it in one of the objectives while
the other time try to defend it. There is a time limit, if the time runs out the team defending
the objectives wins the round, but if the bomb has been planted and the time runs out the
winner will be decided by the outcome of that objective.
To create a map using this game mode you will need to place a bomb spawner
(BP_SearchAndDestroy_BombSpawner) for the attacker team and a couple of objectives
(BP_SearchAndDestroyObjective).
Kill Confirmed
To win one of the teams will need to collect the required dog tags from the other team,
collecting dog tags from your own team will deny the point for the enemies, and to secure a
point collect dog tags from the opposite team.
To create a map for kill confirmed the only requirement is to set the spawns for both teams
and the spawn protection zone is optional.
Rush
To win this game mode the attacker team must destroy the objectives, or the defender team
must kill all the enemy players until they run out of reinforcements, the attacker team will
have a set number of reinforcements and they will lose on point each team a player
respawns.
Rush can have different phases when the attacker team needs to destroy the first set of
objectives before being able to get to the next phase where new objectives will need to be
destroyed. There is a variable in the “BP_PlayerSpawn” called Rush Phase that will be used
only for this mode and the spawns will be usable only if the match is in that phase. First
place the spawn first phase for both teams and the place the spawns for the rest of the
phases, you can have only one phase and ignore this feature or have as many phases as
you want. The default map uses 2 phases, phase 0 and phase 1, if you need an example of
the implementation, you can check it out.
After the spawns are placed, we will need to do the same for the Rush objectives, those also
have the rush phase variable to activate on the correct one.
Team Deathmatch
Gain points by killing the enemy players, the first to get to the required amount will win the
game.
To create a map for Team Deathmatch the only requirement is to set the spawns for both
teams and the spawn protection zone is optional.
FreeForAll
Gain points by killing any other player, the first to get to the required amount will win the
game.
To create a map for Free for all the only requirement is to set the spawns around the map,
make sure that the spawn team variable is set to 0 since in this game mode there are no
teams.
AI
The AI Behaviour tree has always the same structure for all the different game modes, on
one side we will have the combat logic and on the other the game mode specific behaviour.
The behaviour tree of each game mode must be set in the BotManager component located
on the game state for each game mode, and I will be assigned to the AI on spawn.
In every behaviour blueprint the priority goes from left to right so as we can see on the
picture below, the highest priority goes to the combat mode, if the AI has a enemy detected
that Behaviour will run first and if there is no enemy selected the AI will run the Game Mode
behaviour tree, prioritising the game objectives for each mode. In case you make a game
mode that doesn’t use this structure just create a custom behaviour tree from the start or
even reusing part of the code to save some time.
AI Controller
In the AI controller we only handle the possessing of the pawn, unpossess, BeginPlay and
Reset functions. Additionally we use this blueprint to add components like the AIPerception
and AC_KillFeed, the other two (Actions Comp, PathFollowingComponent) come by default
in the blueprint.
Settings Menu
The template comes with all the important settings already implemented so you only need to
change the look, all of that is in the Settings widget.
Audio
In the audio settings we can set the master volume or modify individual channels like the
music volume, ambient volume, etc. It’s recommended to assign one of these groups to
every sound you put in your game.
Maps
The new map system uses sublevels so you can reuse the same environment for more than
one map, or the spawns, or even the lighting. To achieve this you can put everything that is
unique, that you won't reuse for other maps, in the persistent level, like for example the
directional light can be added in the persistent level to make sure that any map has unique
lighting or game mode objectives that are specific for that game mode. In the template the
spawns and the environment are reused in all the game modes except the spawns in
FreeForAll and the Spawns and environment in the Rush game mode.
If you want to make every map completely unique just create everything in the persistent
level, but if you want to use the same map for different game modes use this method so the
changes that you make in one sublevel propagate to all the levels that use this sublevel.
To create a new map using this method put everything unique for that map in the persistent
level, put the environment geometry in another sublevel and the spawns in another one.
UI
The main widget for the UI is the WB_HUD, inside we will find that this widget blueprint is
composed of lots of modular widgets, like the compass, minimap, health bar, match timer,
weapon info, etc.
Health bar widget
Compass
The compass will work by default even without any other component, just uses the character
rotation but has a function to add enemy markers that you will need to trigger.
Minimap
In the minimap we will see our view based on our rotation in the world and some icons for
the objectives and allies. Keep in mind that you will need to make a texture with a picture of
the map to make it work in other maps, this will be explained in detail in the How to’s section.
Damage Overlay
Every time the player gets hit a red screen will show up and if the player gets healed a green
screen will appear, which can be extended to a blue screen in case you gain shield for
example.
Directional Damage
When the player receives damage a direction of the instigator will be shown in this widget for
a few seconds.
Weapon info
This widget will show the current bullets, bullets per mag, total bullets and weapon firing
mode.
HOW TO’s
Create a new level and name it, every map needs the custom spawn “BP_PlayerSpawn”
(keep in mind that you have to set the team for each spawn) and make sure that the player
spawn capsule is not colliding with anything, you can tell if its clipping if the error “BadSize”
appears in the actor.
Another thing that you can add is the spawn protection zone if you want to limit the
movement of enemy players in the spawn zone.
Each game mode it’s going to be different, some game modes don’t need anything else like
free for all, team deathmatch or kill Confirmed, but other game modes like conquest will
need the “BP_ConquestCapturePoint” to be placed in the map to work, rush needs
“BP_RushObjective” to be placed, take a look at the default maps if you need to see an
example or copy the default map and change the name to have all the necessary actors
already in place.
Add the new map to the DT_Maps data table, fill the information and you should be able to
find it in the create game widget with the rest of the maps.
Finally go to Project settings -> Packaging -> Click Packaging/Advanced -> “List of maps to
include in a packaged build” and add your new map there. You can also type “list of maps” in
the search bar to find it.
Minimap
For the minimap texture create a capture scene 2D, place it in the origin of the map and take
a texture using the render target. The ortho width is set to 15000 in the other maps but you
will have to make adjustments if the map is bigger than that, try to always place the middle of
the map in the origin of the map.
Lastly, set go to the end of the BeginPlay Event in the WB_Minimap blueprint to set the map
picture for each game mode.
For every game mode except Free for all you only need to go to the BP_BASE_GS
blueprints and go to the Create bots function to disconnect the input for the bots then you
can set the number of bots that you want to use. For The Free for All game mode you will
need to do the same but this time inside the BP_FreeForAll_GS since CreateBots has been
overridden in this mode.
Useful resources
Unreal Architecture
Gameplay Framework
Player controller
Game Mode and Game State
Pawn
Character
Network Compendium by Cedric ‘eXi’ Neukirchen: here