Multiplayer Game Development with Unreal Engine 5 - Marco Secchi - E-Book

Multiplayer Game Development with Unreal Engine 5 E-Book

Marco Secchi

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

If you’re fascinated by the immersive gaming experiences that enable multiple users to engage in collaborative or competitive gameplay, this Unreal Engine 5 game development book is for you.
In this book, you’ll learn the foundational principles behind multiplayer games. Starting with a sample project, you’ll learn how to set up a networked system and make it work. Once the prototype of the project is functional, you’ll start adding game logic, including obstacles and AI opponents, to heighten the challenges and engagement, offering a captivating experience for players. Next, you’ll learn how to debug and optimize the project, before finally deploying the game build and integrating it with cloud services such as the Epic Online Services system.
By the end of this book, you’ll have the confidence to develop and manage multiplayer experiences using the Unreal Engine environment, taking your newfound programming skills in your upcoming projects.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 449

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Multiplayer Game Development with Unreal Engine 5

Create compelling multiplayer games with C++, Blueprints, and Unreal Engine’s networking features

Marco Secchi

BIRMINGHAM—MUMBAI

Multiplayer Game Development with Unreal Engine 5

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Vaideeshwari Muralikrishnan

Senior Editor: Hayden Edwards

Technical Editor: Simran Udasi

Copy Editor: Safis Editing

Project Coordinator: Sonam Pandey

Proofreader: Safis Editing

Indexer: Sejal Dsilva

Production Designer: Jyoti Kadam

Marketing Coordinators: Namita Velgekar and Nivedita Pandey

First published: October 2023

Production reference: 1300823

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1R

ISBN 978-1-80323-287-4

www.packtpub.com

To my parents, Bruno and Alessandra, for giving me the gift of life..., ... and to my lovely wife, Ambra, for making it wonderful.

– Marco

Contributors

About the author

Marco Secchi is a passionate game programming teacher based in Milan, Italy. Previously, he was a freelance programmer, focusing on game and application development; currently, he is a lecturer and lead game advisor at Nuova Accademia di Belle Arti (NABA). Marco continues to hone his programming skills in the research and development department at NABA, while also working on personal projects, involving game development and cultural heritage.

I want to thank the people who have been close to me and supported me while writing this book, especially the amazing people at Packt (they made writing this book much easier than I thought).

About the reviewers

Gonçalo Marques has been an active gamer since the age of six. He has used Unreal Engine since 2016 and has done freelance and consulting work using the software. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered extremely positive reception, with over 100,000 downloads, and still receives frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrants recipient. He now works at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.

Punya Aachman is a talented gameplay programmer and technical artist with four years of experience in the gaming industry. He has worked on game titles, simulations, and other various projects, bringing to life engaging gameplay mechanics, immersive experiences, and efficient game development tools on various platforms, such as PC, Oculus Rift, and PlayStation VR. His expertise includes game engines such as Unreal Engine and digital content creation software such as Blender, as well as programming languages such as C++ and Python. Aachman has also contributed to the open source tools community for Blender. With a drive to innovate and a passion to push the boundaries of what’s possible in games, Aachman is a valuable asset to any project.

Table of Contents

Preface

Part 1: Introducing Multiplayer Games

1

Getting Started with Multiplayer Game Development

Technical requirements

Pre-requisite knowledge

Hardware requirements

Software requirements

Introducing multiplayer games

Becoming a network programmer in video games

Understanding multiplayer game categories

First-person shooters

Third-person shooters

Real-time strategy

Massively multiplayer online role-playing games

Multi-user dungeons

Multiplayer online battle arena

Reviewing gameplay twists

Asymmetrical gameplay

Hide-and-seek gameplay

Asynchronous gameplay

Is multiplayer technology just for games?

Cinematography

Architecture

Education

Unreal’s Collab Viewer template

Summary

2

Understanding Networking Basics

Technical requirements

What is computer networking?

Types of computer networks

Local Area Networks

Wide Area Networks

Virtual Private Networks

Introducing network protocols

Packet switching

TCP/IP suite

Understanding network issues

Security

Packet loss

Latency

Introducing the Unreal Engine multiplayer system

Network modes and server types

The replication system

Network role

Pawns and PlayerControllers

Relevance and priority

Remote Procedure Calls

Summary

Credits

3

Testing the Multiplayer System with a Project Prototype

Technical requirements

Creating a multiplayer game prototype

Setting up the project from a template

Adding Quixel Megascans

Modifying the Player Controller

Testing a multiplayer game locally

Playing as a Listen Server

Updating over the network

Adding additional character spawn points

Updating properties over the network

Creating the pickup Blueprint

Adding pickup variants

Adding a points counter to the character

Executing functions over the network

Spawning Actors

Skinning characters

Testing the game

Summary

Part 2: Networking and Multiplayer Games in Unreal Engine

4

Setting Up Your First Multiplayer Environment

Technical requirements

Introducing Unreal Shadows – Legacy of the Lichlord

Explaining the project brief

Starting the project

Understanding C++ in Unreal Engine

Blueprints and C++

Understanding C++ classes

Anatomy of a UE C++ header

The Unreal Engine Reflection System

Memory management and garbage collection

Starting your Unreal multiplayer project

Creating your project file

Creating the project game instance

Creating the Game Mode and the Game State

Adding the player classes

Compiling your source code

Creating the Character Blueprint Class

Adding the Player classes to the Game Mode

Summary

5

Managing Actors in a Multiplayer Environment

Technical requirements

Setting up the character

Adding basic settings to the character

Adding interaction to the character

Importing the Enhanced Input Module

Adding user interaction to the character

Testing the character’s movement

Controlling the connection of an Actor

Understanding Actor relevancy

Understanding relevancy

Testing relevancy

Testing the relevancy settings

Introducing authority

Controlling authority with the Role and Remote Role properties of an Actor

Autonomous and simulated proxy

Summary

6

Replicating Properties Over the Network

Technical requirements

Adding character stats

Creating the stats structure

Creating a stats data table

Reading the data table from the character

Adding the data table to the character

Understanding property replication

Enabling property replication

Referencing Actors and components over the network

Handling character level-ups

Planning ahead

Declaring PlayerState properties and functions

Implementing the PlayerState logic

Adding coin pickups to the level

Adding a HUD to the game

Creating the Widget Blueprint

Adding code logic to the Widget Blueprint

Adding the HUD to the character

Testing the game

Summary

7

Using Remote Procedure Calls (RPCs)

Technical requirements

Understanding what an RPC is

Reliability of an RPC

Validating RPCs

Executing RPCs over the network

Calling a function on the server

Implementing a door system

Creating the Interactable interface

Implementing the interact action

Creating the door Blueprint

Testing the interact action

Summary

Part 3: Improving Your Game

8

Introducing AI into a Multiplayer Environment

Technical requirements

Setting up the AI system

Creating an AI opponent

Adding the navigation module

Creating the minion class

Implementing the minions’ behaviors

Adding opponents to the level

Creating a spawner class

Testing the spawner

Summary

9

Extending AI Behaviors

Technical requirements

Making AI opponents more challenging

Making some noise

Enabling the hearing sense

Testing the hearing sense

Implementing an alert system

Declaring the Game Mode functions

Making the AI send alert messages

Adding health to the AI

Adding a weapon system to the character

Creating a dagger projectile

Implementing the weapon component

Attaching the WeaponProjectile component to the character

Adding an input system for the weapon

Testing the weapon system

Creating AI variations

Creating an AI sentinel

Creating an AI miniboss

Updating the minion spawner

Summary

10

Enhancing the Player Experience

Technical requirements

Animating the character

Creating the animation assets

Adding the Animation System to the character

Adding the throw animation

Adding NPC Actors

Creating the NPC character

Testing the NPC Actor

Making further improvements to the game

Let’s make some noise!

I need a key!

Improve your arsenal, my hero!

You are not a machine gun

No time to waste

Tables, tables everywhere!

Need some help?

Summary

11

Debugging a Multiplayer Game

Technical requirements

Introducing network debugging

Explaining game debugging

Introducing multiplayer options

Logging in a networked environment

Filtering the LogNet category

Creating a custom log category

Emulating a networked environment

Enabling network emulation

Testing the game with network emulation

Using the Network Profiler

Recording a profiling session

Analyzing a profiling session

Improving performance and bandwidth utilization

Turning on replication only when necessary

Avoiding invoking RPCs that are not required or essential

Distinguishing between reliable and unreliable RPCs

Validating data

Remembering that the GameMode exists only on the server

Using a naming convention for RPCs

Summary

Part 4:Deploying Your Game Online

12

Managing Multiplayer Sessions

Technical requirements

Understanding game sessions

Introducing the Online Subsystem

Understanding session commands

Understanding connection errors

Preparing a project game session

Creating a session

Adding the visual elements

Implementing the Visual Scripting logic

Joining a session

Creating the SessionItemRenderer widget

Creating the FindSessions widget

Creating the Main Menu widget

Summary

13

Handling Data During a Session

Technical requirements

Creating the main menu level

Creating the Pawn

Creating the GameMode

Creating the level

Testing the session system

Handling data during a session

Updating the US_GameInstance class

Adding the CharacterSkins data

Updating the US_MainMenuPawn class

Updating the BP_MainMenuPawn Blueprint

Updating the US_Character class

Updating the BP_Character Blueprint

Making further improvements

Leaving and destroying sessions

Handling player death

Selecting the player skin

Summary

14

Deploying Multiplayer Games

Technical requirements

Going online for real

Compiling the Unreal Engine

Downloading the Unreal Engine source project

Compiling from the source code

Setting up a dedicated server

Creating the project

Building the project solution

Building the dedicated server

Testing the project

Summary

15

Adding Epic Online Services (EOS)

Technical requirements

Introducing EOS

Accessing the Developer Portal

Accessing the Epic Games Developer Portal

Creating a Product

Configuring the Product services

Getting started with the EOS SDK

Downloading the EOS SDK

Integrating the system into your game

Summary

Index

Other Books You May Enjoy

Part 1:Introducing Multiplayer Games

In the first part of book, you will receive a beginner-friendly introduction to the realm of multiplayer game development. Once you have a solid understanding of its key concepts, you will proceed to construct a functional prototype of a multiplayer game.

This part includes the following chapters:

Chapter 1, Getting Started with Multiplayer Game DevelopmentChapter 2, Understanding Networking BasicsChapter 3, Testing the Multiplayer System with a Project Prototype

1

Getting Started with Multiplayer Game Development

Welcome to the wonderful world of multiplayer game development in Unreal Engine! I am really excited that you have selected me and my book as a guide to this sometimes scary technology; I promise that I’ll do my best to make this journey as easy and as entertaining as possible.

Throughout the book, you will learn how to create an Unreal Engine multiplayer game from scratch, handle client/server logic, manage AI opponents, test and profile the network, and take advantage of available cloud services. By the end, you will be proficient in creating a networked video game and have a deep knowledge of many of the pitfalls and how to avoid them.

In this chapter, you will get an overview of what a multiplayer game is, its origins, and the different types of multiplayer games that are available today. Additionally, you will explore how the technology used in multiplayer games has been applied in contexts outside of gaming.

In this chapter, I will discuss the following topics:

Introducing multiplayer gamesUnderstanding multiplayer game categoriesExploring gameplay twistsIs multiplayer technology just for games?

Technical requirements

As you may already know, the Unreal Engine Editor may be very demanding in terms of hardware prerequisites but don’t be scared. Luckily, this book is more focused on game programming than on real-time visual effects.

Here, let’s look at the hardware and software requirements, as well as some pre-requisite knowledge you will need to follow this book.

Pre-requisite knowledge

Before you get started, it is my duty to remind you that this book is meant for people who already have some knowledge about Unreal Engine development. As such, you should already be familiar with the following topics:

The Epic Games Launcher and the Unreal Engine EditorBlueprint classes and Blueprint programmingC++ programming with your IDE of choiceA minimum level of understanding of C++ programming with Unreal Engine.

Hardware requirements

The following are some basic requirements officially recommended by Epic Games at the time of writing this book; if you have at least this hardware, you should be guaranteed a nice experience throughout the chapters:

Windows OS:Operating System: Windows 10 64-bit version 1909 revision .1350 or higher, or versions 2004 and 20H2 revision .789 or higherProcessor: Quad-core Intel or AMD, 2.5 GHz or fasterMemory: 8 GB RAMGraphics Card: DirectX 11- or 12-compatible graphics cardLinux:Operating System: Ubuntu 22.04Processor: Quad-core Intel or AMD, 2.5 GHz or fasterMemory: 32 GB RAMVideo Card: NVIDIA GeForce 960 GTX or higher with the latest NVIDIA binary driversVideo RAM: 8 GB or moremacOS:Operating System: Latest macOS VenturaProcessor: Quad-core Intel, 2.5 GHz or fasterMemory: 8 GB RAMVideo Card: Metal 1.2-compatible graphics card

In my case, I’ve been writing this book with the following hardware:

Desktop:Operating System: Windows 10 64-bit versionProcessor: Intel Core i9 9900K @3.60GHzMemory: 64 GB RAMGraphics Card: NVIDIA GeForce RTX 3090tiLaptop:Operating System: Windows 10 64-bit versionProcessor: Intel Core i7 9750H @ 2.60GHzMemory: 16 GB RAMGraphics Card: NVIDIA GeForce RTX 2070

Software requirements

This book assumes you have the Epic Games Launcher and Unreal Engine 5 installed and fully working on your computer.

Note

At the time of writing this book, the latest version of Unreal Engine is 5.1.1 but you will be able to follow along with any version more recent than 5.1.1.

Additionally, you’ll need an IDE supporting C++ and Unreal Engine. If you already have some past experience, chances are you have already installed Visual Studio 2019/2022 or JetBrains Rider; if you don’t, you will need to install one of them by the start of Chapter 4, Setting Up Your First Multiplayer Environment.

Note

This book assumes you have Visual Studio 2019 or 2022 installed and fully functional; however, it’s totally fine to use JetBrains Rider.

Setting up Visual Studio for Unreal Engine development

Once you have Visual Studio installed, you’ll need the following extra components to make it properly work with Unreal Engine:

C++ profiling toolsC++ AddressSanitizerWindows 10 SDKUnreal Engine installer

To include these tools, follow these steps:

Open Visual Studio Installer.Select Modify from your own Visual Studio installation, selecting the version you will be using, as shown in Figure 1.1:

Figure 1.1 – Visual Studio Installer

Once the Modifying modal window opens, in the top bar, make sure you are in the Workloads section.Then, activate the Game development with C++ option by clicking the checkmark.Next, if it is closed, open Installation details | Game development with C++ | Optional from the right sidebar.Select C++ profiling tools, C++ AddressSanitizer, the latest Windows 10 SDK version available, and Unreal Engine installer, as shown in Figure 1.2.

Figure. 1.2 – Visual Studio with Unreal Engine installer activated

Click the Install while downloading button (or the Download all, then install button) to start the installation process.

Once the download and installation process is finished, you will be ready to develop your own C++ games with Unreal Engine.

IDE support for Unreal Engine

Microsoft has recently introduced a new Unreal Engine integration extension for Visual Studio 2022 called IDE Support for Unreal Engine. This tool adds some new features such as Blueprint references, Blueprint assets, and CodeLens hints on top of Unreal Engine classes, functions, and properties.

To include this tool, follow these steps:

Open the Workloads section if it has been closed.Activate the Game development with C++ option by clicking the checkmark.If it is closed, open Installation details | Game Development with C++ | Optional from the right sidebar.Select IDE support for Unreal Engine, as shown in Figure 1.3.

Figure 1.3 – Installing the IDE support

Now install the tool.

Now that your IDE is properly configured, it’s time to gain some understanding of where multiplayer games come from. In the next section, you’ll learn a little bit of video game history.

Introducing multiplayer games

Multiplayer games are probably one of the most attractive forms of entertainment available today. There are several reasons why these types of games have become so popular and engaging over the years.

First, playing with other people adds elements of competition (or cooperation) that can be incredibly motivating and fun. Whether it’s a game such as the hyper-realistic Counter-Strike: Global Offensive (https://www.counter-strike.net/) or some crazy setting such as Rubber Bandits (https://www.rubberbandits.game/), there is something magical about playing in virtual environments that makes it exciting and enjoyable.

Having someone else to play with also means introducing a lot of opportunities for creative problem-solving and many possibilities for social interaction between people from different backgrounds and countries who may never have met otherwise!

But how did it all begin?

In the early 70s, the PLATO time-sharing system developed by the University of Illinois and Control Data Corporation enabled students at multiple locations to access online lessons. Soon after the introduction of PLATO IV, students began utilizing the newly introduced graphical capabilities to create multiplayer video games. By the end of the 70s, PLATO had introduced different games, spanning from dungeon crawlers to space battles to tank combat.

However, multiplayer games didn’t really take off until the mid-90s: at this time, internet access became widely available and gamers could finally connect to each other throughout the world.

The popular Doom is considered the very first online game as it allowed up to four players at once and featured a deathmatch mode where you could compete for points.

Over the decades, technology has massively improved and we are now able to play together around the globe in amazing immersive virtual worlds without (hopefully!) any lag or connection issues: it’s no wonder so many people are drawn toward these types of experiences!

What’s more, gamers have developed creative ways to communicate during gameplay, such as using online services including Skype and Discord, which deliver an even more immersive experience.

With the advent of real-time streaming platforms such as Twitch and YouTube, a new phase of multiplayer games has begun. Gamers can play and live broadcast at the same time, letting millions of people enjoy their experience.

Becoming a network programmer in video games

If you are reading this book, chances are you want to understand the basic principles of networking and apply your soon-to-be strong knowledge in multiplayer video game programming to the next big hit. As a multiplayer programmer, you will be able to create fun and interactive games for others to enjoy: this will be an incredibly rewarding experience!

But be aware – network video game programming can be quite challenging, with long work hours and potential stress. It is important to be aware of this before pursuing this type of career.

To avoid these kinds of pitfalls, it’s essential to have a solid understanding of how networks work in order to let players have an enjoyable and flawless experience.

Understanding a multiplayer game also means understanding how to troubleshoot computer issues and handle them whenever they pop up.

And rest assured...they will pop up sooner or later!

In the following section, you will learn about the major types of multiplayer games, as well as the distinctions that set them apart.

Understanding multiplayer game categories

There is a wide array of game categories available to choose from, ranging from first-person shooters to role-playing; often, a game incorporates more than one genre, giving the player exactly what they are looking for. Here you will find a non-exhaustive list of the most popular game types available nowadays, describing them from a multiplayer point of view.

First-person shooters

First-person shooter (FPS) titles are probably some of the most exciting and immersive video games available on the market and involve, as the name suggests, playing from a first-person perspective using various types of weapons.

Players will experience virtual worlds through the eyes of the character with mechanics such as running, taking cover, aiming, shooting (and often reloading your weapon!); this means having fast reflexes or you’ll be out of business really quickly!

Multiplayer FPS games offer several game modes that can be played as co-op campaigns, such as capture the flagor deathmatches.

There are countless multiplayer FPS games available, but Apex Legends (https://www.ea.com/games/apex-legends) and Call of Duty (https://www.callofduty.com/) are good examples of this popular genre.

Third-person shooters

Third-person shooter (TPS) games are very similar to FPS games but players can battle each other from a third-person perspective. While FPS games tend to be more focused on shooting opponents and completing objectives, TPS games offer the player a wider view of the surrounding world, making them a good choice for more strategically oriented users.

One of the most popular features with both FPS and TPS games is the ability to change the skin of your character, allowing the creation of unique avatars that will stand out from the crowd.

Fortnite (https://www.fortnite.com/) by Epic Games (the developer of Unreal), is one of the most played TPS games, with millions of players around the world every day.

Real-time strategy

Real-time strategy (RTS) games combine elements of competition and strategy in a multiplayer experience. Usually, players must build an army and interact with other players online, often involving managing resources, forming pacts with other people (while trying to outsmart them!), and obviously, attacking them when it’s clear that there can be only one left standing!

One of the most successful and popular RTS games of all time is StarCraft (https://starcraft.com/), where players control one species and must battle the others for power and dominance.

Massively multiplayer online role-playing games

In a massively multiplayer online role-playing game (MMORPG), the classic role-playing game is augmented with networked features allowing thousands (or even millions) of players to interact in real time.

One of the most exciting things about MMORPGs is the ever-changing flow of the story as players will influence it with their own actions; they will buy equipment, hone their skills, and form alliances while looking for the next adventure.

World of Warcraft (https://worldofwarcraft.blizzard.com/) is undeniably one of the most popular and longest-running games in this genre.

Multi-user dungeons

Multi-user dungeon (MUD) games can be considered the progenitors of MMORPGs and are text-based adventures where each player takes the role of an adventurer in a virtual world. MUDs usually include elements of role-playing, strategy, and hack-and-slash games.

Although they may seem a bit old-fashioned, MUDs are still widely played thanks to their active communities, where players form strong relationships over the years.

Sometimes, MUDs are created by groups of fans of a fictional genre such as DiscWorldMUD (https://discworld.starturtle.net/), a game based on the DiscWorld saga created by Terry Pratchett.

Multiplayer online battle arena

Multiplayer online battle arena (MOBA) games are a strategy subgenre where two teams compete against each other: each player controls a character trying to defeat the opposing team, usually by destroying the enemy base. Arenas are predefined, letting teams plan their strategies in advance.

MOBAs also usually feature non-player character (NPC) minions controlled by artificial intelligence (AI) that will help characters achieve their goals.

One of the most played MOBA games is League of Legends (https://www.leagueoflegends.com/), which has been around since 2009 and is still a favorite among players around the world.

Note

The game examples I have provided here have obviously been developed by dozens (if not hundreds) of people, and creating these kinds of games is obviously outside the scope of this book. Additionally, some genres – such as MMORPGs – are some of the most complex and ambitious video games to make. With this in mind, you should exercise caution before attempting to create an intricate multiplayer game – first of all, ensuring that you possess the necessary skills and confidence to handle its vast scope.

Now that we have looked at the different multiplayer genres available, in the next section, you will discover how these genres can be enhanced with creative additions that can completely transform the way they are played.

Reviewing gameplay twists

Given all the aforementioned options available, it is simply a matter of personal preference which multiplayer game genre a player chooses. However, as a developer, you need to be aware of different types of gameplay and technologies to make your project work properly. In this section, I will present a couple of twists applied to regular gameplay.

Asymmetrical gameplay

In asymmetric multiplayer games, two or more teams of players compete in gameplay where the mechanics are different for each group. These games usually require players to set their strategy depending on their chosen side.

One of the best examples is Among Us (https://www.innersloth.com/games/among-us/), which is set on a spaceship where some player takes the role of an impostor whose aim is to let all other crewmates die in some “unexpected” accident before their true identity is revealed.

Hide-and-seek gameplay

There are some games that are meant to be open-ended, letting players explore worlds with considerable freedom and achieve more objectives compared to other more linear adventures.

In multiplayer games, this has led to some hide-and-seek variants, where players try to avoid each other (or the main storyline), whether the game officially supports them or not.

An example of this kind of twist is Secret Neighbor (https://www.secretneighbor.com/), a multiplayer social game where a group of adventurous kids is trying to sneak into their mysterious neighbor’s home to uncover evidence that suggests he is keeping children captive.

Asynchronous gameplay

An asynchronous multiplayer game will let players interact with each other without the need to be connected at the same time. These games are usually played in turns, where each player will make their move and will wait for the opponent to complete the next one.

And yes...online chess is an asynchronous game!

Now that you have a strong understanding of the main networked game genres, you may be wondering whether game engines’ multiplayer technologies are just for gaming. In the next section, I will provide some examples that demonstrate the opposite.

Is multiplayer technology just for games?

As you have read so far, multiplayer networking is an incredibly powerful tool for creating immersive and entertaining games. However, you may be wondering whether this technology is just about gaming.

The short answer is no.

The networking technology available in game engines such as Unreal Engine can be an incredibly useful tool beyond just gaming. Collaborating remotely in real time can have a huge impact on productivity and can be applied to almost any type of project, ranging from educational purposes to architecture, up to cinematography.

Cinematography

Multiplayer technology has become more and more important in movie productions with the advent of virtual production (VP).

VP is a workflow that combines computer-generated imagery (CGI), motion capture, and real and virtual assets combined in a real-time visualization. VP enables content creators (usually filmmakers) to have more efficient and cost-effective productions.

One of the best examples of multiplayer technology used in a VP pipeline is virtual scouting, which is the process of exploring and evaluating potential shooting locations without leaving their own studios. This is usually leveraged by a mix of augmented reality (AR) and virtual reality (VR).

A good example of using Unreal Engine in VP can be found in The Mandalorian series for the streaming service Disney+.

Architecture

Unreal Engine can be used in architecture to create real-time interactive visualizations of architectural projects. These simulations can be run on a multiplayer networking system providing online collaboration capabilities between architects. During the design process, architects can use Building Information Modeling (BIM) technology in a networked system to access the same model and make changes simultaneously, being more collaborative and efficient.

Real-time rendering software with multi-user capabilities helps designers and architects connect with stakeholders in every phase of the Architecture, Engineering, and Construction (AEC) life cycle, enabling faster, better communication.

Reflect (https://unity.com/products/unity-reflect), a service developed by Unity Technologies, is a good example, letting users experience virtual environments with a mix of 3D rendering, VR, and AR.

Education

Unreal Engine’s multiplayer capabilities can be an amazing tool for educators and students, providing immersive and interactive learning experiences. Any teacher with some practical knowledge of the game engine can create a virtual classroom where students can interact with each other in real time.

Games such as Fortnite and its Fortnite Creative version (https://www.fortnite.com/creative) have been used lately as an educational tool in many schools, letting students develop problem-solving skills and engaging them in a fun way.

Unreal’s Collab Viewer template

The Unreal Engine Editor has a couple of excellent templates that can be immediately applied as a networked collaborative environment: Collab Viewer for Architecture and Collab Viewer for Automotive, Product Design and Manufacturing.

In Figure 1.4, you can see Collab Viewer for Architecture selected and ready to be generated:

Figure 1.4 – The Collab Viewer template selected in Unreal Editor

These project templates provide an amazing starting point for collaborative industrial and architectural projects; everything has already been set up (even a login panel to access the application), so all you have to do is add your own environment and export the application.

As a teacher, I have often used these Unreal Engine templates as a quick way to create multiplayer educational experiences such as virtual museums or for displaying students’ projects.

Figure 1.5 shows the application in action emulating three users on a single machine (don’t worry, we will get back to this very soon!).

Figure 1.5 – Collab Viewer in action

Knowing how to use Collab Viewer and its many features (VoIP, real-time annotations, VR mode, etc.) is beyond the scope of this book, but if you are interested in this topic, Epic Games has an exhaustive section in the Unreal Engine documentation: https://docs.unrealengine.com/5.1/en-US/collab-viewer-templates-in-unreal-engine/.

Summary

In this chapter, you have been introduced to the main categories of multiplayer games and why it is so important to have a solid understanding of networking in the present day. What’s more, you were provided with a brief overview of practical examples that extend the concept of something that is traditionally considered a game-only field.

In the next chapter, I will guide you through the basic principles of networking. Although you will encounter a substantial amount of information (which may seem somewhat theoretical), rest assured that it will all become clear as you progress to Chapter 3, Testing the Multiplayer System with a Project Prototype, where you will start creating your first multiplayer prototype.

2

Understanding Networking Basics

Having a strong knowledge of networking is the foundation of any successful multiplayer game development, as it provides a basic understanding of how the different components that make up a network work. Networking can be divided into three main areas: logical architecture, protocols and standards, and physical infrastructure.

As it’s important for anyone interested in networked games to have at least some basic understanding of these concepts, the primary goal of this chapter is to introduce you to these components and the main issues that may pop up during multiplayer application development. By the end of the chapter, you will also get a grip on how the Unreal Engine multiplayer framework is organized in order to be prepared for the next step: creating your first multiplayer game prototype.

So, in this chapter, we will cover the following topics:

What is computer networking?Introducing network protocolsUnderstanding network issuesIntroducing the Unreal Engine multiplayer system

Technical requirements

There are no technical requirements to follow in this chapter.

What is computer networking?

We live in a world where we are constantly communicating with each other through computers, smartphones, smart homes, and a plethora of different devices. Computer networks are the backbone of modern technology.

Most people probably don’t even care about device communication and how it works; the most important thing is that... well, it works. But what exactly does network mean? And most importantly, as multiplayer game developers, what do we need to know about network systems?

Computer networking involves two or more (most of the time, a lot more!) devices that are connected together with the common goal of sharing data and resources as fast and as reliably as possible.

A network can use cables (wired) or radio waves (wireless) and can cover a self-enclosed area or be available at a greater scale. Even if all these technologies share the same purpose, their structure and capabilities will vary significantly.

Once devices are physically connected, they must establish a “contract” in order to communicate securely; without such a contract, data could be sent to the wrong person and put important information at risk.

After the contract is established, each device can send data to another one using a “digital envelope” that identifies the sender and the receiver. This ensures that the data is only received by the intended recipient.

Dispatching data over the network can be very complex, especially when dealing with large files (think about an email with a 150 MB 3D model as an attachment and you’ll probably get the idea!). As a consequence, data must be “fragmented” into small pieces by the sender and, once it arrives at its destination, it will be re-packaged by the receiver, ready to be used.

This brings us to the last stage: losing information. Despite the advancements in technology, data loss is still a possibility in our imperfect world. Data can be corrupted or lost during transfer; therefore, it is important to take measures to ensure the safety of data and prevent such losses.

If things sound difficult, that's because they are! But don’t be afraid, that’s exactly how I felt when I started learning about this type of technology; as you make your way through this book, you will find that many of the topics have been handled by the UE multiplayer system, leaving you free to explore higher level topics.

In the next section, you will learn how a network, or a group of networks, is organized from a structural and operational perspective.

Types of computer networks

As you already know, a computer network provides a way for multiple devices to communicate by sharing information with each other. Some well-known examples are as follows:

Sending emailsStreaming videos...and guess what? Playing online games!

But how are these devices connected? There are several different types of computer networks available that have different capabilities and purposes; depending on your needs (and your budget!), you’ll have to find a solution that will grant you reliability and trustworthiness.

Local Area Networks

Local Area Networks (LANs) are probably the most common type of computer network. A LAN usually consists of a telecommunication network that connects devices that are situated at a close distance (usually no more than 1 kilometer). This type of network usually takes advantage of the fast connection over short distances granted by Ethernet cables.

A LAN can be of two types:

A client/server LAN, where several devices (i.e., the clients) are connected to a centralized computer (i.e., the server)A peer-to-peer LAN, where each device shares the network functionalities equally

Figure 2.1 illustrates a typical small-sized LAN where devices are connected through Wi-Fi or Ethernet cables.

Figure 2.1 – A LAN setup

One of the main advantages of a LAN over a Wide Area Network (WAN) is the lower level of maintenance and reduced implementation costs. Also, since a LAN is limited to a relatively small distance and to a limited number of connected devices, it ensures a higher level of security.

Some good examples where LANs are used are academic campuses (sometimes called Campus Area Networks), hospitals, or offices with multiple departments.

A LAN can become a Wireless Local Area Network (WLAN) when connections between devices are only made wirelessly, and it is typically used in homes or public spaces (for example, libraries, airports, and cafes) where devices must connect without the need for physical cables.

Wide Area Networks

The primary difference between a LAN and a WAN is that a WAN covers a much larger area and is essentially a collection of LANs connected together.

Similarly for the LAN, a WAN can be as follows:

A client/server WAN, where multiple devices are connected to a central computerA peer-to-peer WAN, where each device shares an equal responsibility in the network functionalities

As there is usually a loss in speed over long distances, a WAN is typically slower than a LAN. However, the main advantage of a WAN is the capability to be publicly owned: a good example is the internet, where no entity has full ownership.

Figure 2.2 shows several LANs connected together through a WAN:

Figure 2.2 – A WAN setup

A Metropolitan Area Network (MAN) is a smaller WAN usually managed by cities, regions, or governments; it typically includes a high-speed backbone network, which connects multiple LANs. As an example, it may connect multiple campuses belonging to the same academic institution (and that’s how it works where I am teaching right now!).

Virtual Private Networks

A Virtual Private Network (VPN) is a secure connection over the internet from a device to a network. By using secure encryption, data sent over a VPN is protected, preventing unauthorized tracking, protecting privacy, and bypassing geo-restrictions.

Figure 2.3 shows an example where a device connected to a LAN is communicating over the internet with another device through a VPN.

Figure 2.3 – A VPN example

In this section, you have been introduced to the fundamental principles of computer networking. You have explored how computer networks are structured and organized. In the following section, you will delve deeper into these topics to understand how devices communicate using rules and protocols, and how these rules guarantee the reliability and accuracy of the data that is exchanged.

Introducing network protocols

To manage communication between two or more computers, we need some rules that will dictate how data is sent and received, as well as security measures that need to be taken to ensure reliability. These rules are called protocols.

Putting it simply, a protocol is like an international language: everyone needs to know the same words to communicate with one another. More specifically, a network protocol is a set of directives that rules how to format, transmit, and receive data so that devices in the same network can interact.

But before transmitting data over the network, it should be carefully packaged and structured so that the receiver can recognize and reassemble it.

Packet switching

Packet switching refers to the method of sending data to a network in the form of small portions (or packets). This process involves dividing data into small segments and adding an extra portion of information about the packet’s content, origin, and destination. This extra information is called a header and is typically placed at the front of each packet. In some cases, the packet may also include additional information at its end, referred to as a footer.

These packets are then sent over the network and reassembled at their destination. Along the way, they are processed by intermediate nodes, which can store incoming data and forward it to the next node closer to the final receiver.

Some of the advantages of using packet switching include efficiency in terms of bandwidth and reliability as the receiver can detect missing packages. Another advantage is cost-effectiveness due to relatively cheap implementation.

As an example, Figure 2.4 shows a Transmission Control Protocol (TCP) packet composed of its header and data sections:

The header is made of blocks of bits, each one with its own meaning (as an example, the header length tells the header data offset in order to specify where actual data will start in the sequence)The data can be of varying lengths and holds the actual content included in the packet

Figure 2.4 – A TCP packet

The collection of protocols that rule how data should be packaged and forwarded through the network is now known as the Internet Protocol Suite or the TCP/IP suite.

TCP/IP suite

The TCP/IP suite is made of different logical levels, or layers, that are stacked one above the other. These include the following:

The application layerThe transport layerThe internet layerThe data link layer

Figure 2.5 shows the layers of the TCP/IP suite with some of the most commonly used protocols, along with the physical layer, which we will discuss later in this section:

Figure 2.5 – TCP/IP layers

Each layer has an important role to play in supporting the needs of the one above it. As an example, this may involve accepting a block of data from the layer above, processing it according to the current layer’s protocols, and then sending it to the layer below.

Let’s take a look at each of these layers now.

The application layer

The application layer provides the interface for communication between applications running on different machines on the network. It stands at the very top of the TCP/IP suite and allows the sharing of data through the use of protocols, such as the File Transfer Protocol (FTP) and the HyperText Transfer Protocol (HTTP), which are used to upload files to the internet and download web pages on your favorite browser.

The transport layer

The transport layer is responsible for providing reliable data delivery and flow control and provides services that allow applications to communicate securely over the network.

While TCP is commonly used for its reliability, there are situations where other protocols are preferred for their speed, such as the User Data Protocol (UDP), which won’t ensure packet delivery but will be faster as it doesn’t require the overheads associated with establishing and maintaining a connection.

This layer is typically responsible for detecting issues and verifying data integrity; one way is through checksums, or sequences of numbers and letters used to check data for errors.

The internet layer

The internet layer (or, more generically, the network layer in the TCP/IP suite) is responsible for providing the means to route data between different networks and ensure that packets are delivered correctly. This layer also provides various services such as addressing, routing, congestion control, and flow control.

The internet layer is responsible for providing a logical addressing system that allows hosts to be easily replaced, groups of hosts to be organized into subnets, and distant subnets to be able to communicate with one another.

The most common protocol used to implement these features is Internet Protocol Version 4 (IPv4), which is a 32-bit address that identifies a device on a network. The most recent release, Internet Protocol Version 6 (IPv6), is based on a 128-bit address and is designed to replace IPv4, as that one is running out of available addresses.

The data link layer

The data link layer is responsible for providing a method for communication between physically connected hosts. This means this layer must provide a method through which a source host can package up information and transmit it through the physical layer.

Figure 2.6 depicts a typical communication flow between two devices, a client and a server, and the data passing through the different layers:

Figure 2.6 – The communication between a client and a server

The physical layer

Underneath all of the previous layers is the physical layer, which is responsible for actually sending raw data (bits) over a physical medium, such as a cable, an optical fiber, a Wi-Fi connection, or even a Bluetooth communication.

This layer defines how signals are sent and received, as well as how these signals are modulated and demodulated into usable digital information.

Though we have discussed the physical layer here, it is not actually included in the TCP/IP suite, which is why it is slightly separated from the other layers shown in Figure 2.5.

Now that you know how data is packaged and how the TCP/IP suite is organized, you will learn about the main problems and pitfalls that can happen over the network in the next section.

Understanding network issues

With so much data involved and moving around physical media, there is a significant risk of running into serious issues. As such, it is important to be aware of these potential problems and how to best avoid them or limit their impact.

Security

The first issue