Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unreal Engine 5 Game Development with C++ Scripting

You're reading from  Unreal Engine 5 Game Development with C++ Scripting

Product type Book
Published in Aug 2023
Publisher Packt
ISBN-13 9781804613931
Pages 384 pages
Edition 1st Edition
Languages
Author (1):
ZHENYU GEORGE LI ZHENYU GEORGE LI
Profile icon ZHENYU GEORGE LI

Table of Contents (18) Chapters

Preface 1. Part 1 – Getting Started with Unreal C++ Scripting
2. Chapter 1: Creating Your First Unreal C++ Game 3. Chapter 2: Editing C++ Code in Visual Studio 4. Chapter 3: Learning C++ and Object-Oriented Programming 5. Chapter 4: Investigating the Shooter Game’s Generated Project and C++ Code 6. Part 2 – C++ Scripting for Unreal Engine
7. Chapter 5: Learning How to Use UE Gameplay Framework Base Classes 8. Chapter 6: Creating Game Actors 9. Chapter 7: Controlling Characters 10. Chapter 8: Handling Collisions 11. Chapter 9: Improving C++ Code Quality 12. Part 3: Making a Complete Multiplayer Game
13. Chapter 10: Making Pangaea a Network Multiplayer Game 14. Chapter 11: Controlling the Game Flow 15. Chapter 12: Polishing and Packaging the Game 16. Index 17. Other Books You May Enjoy

Making Pangaea a Network Multiplayer Game

Unreal Engine was initially developed for the Unreal first-person shooter (FPS) game in 1998, and the game’s multiplayer mode allowed up to 16 players to join a session. Owing to the game’s popularity, Epic Games released Unreal Tournament in 1999, and it was one of the most popular multiplayer shooter games.

Multiplayer support is one of the key strengths of Unreal Engine; it is, in fact, one of the reasons why the engine is so popular and successful. This chapter will walk you through the steps to convert Pangaea into a multiplayer game so that you can learn how to start the game as a server or a client, synchronize game states, and send messages between the server and connected clients.

We will cover the following topics in this chapter:

  • Comparing single-player and multiplayer games
  • Launching the multiplayer Pangaea game in the editor
  • Understanding multiplayer game network modes
  • Handling network synchronizations...

Comparing single-player and multiplayer games

A single-player game runs on a local machine (PC, game console, and so on) as a standalone application. The player interacts with the game directly through one or more connected input devices (keyboard, mouse, game pad, and so on). The game simulation is handled on the local machine. Here’s how its setup looks:

Figure 10.1 – Single-player game

Figure 10.1 – Single-player game

As with single-player games, a local multiplayer game runs on a local machine as a standalone application. The game allows multiple players (usually one to four players) to play the game together and interact with the game directly through their input devices. The game simulation is still handled on the local machine. The setup looks like this:

Figure 10.2 – Local multiplayer game

Figure 10.2 – Local multiplayer game

A network multiplayer game allows multiple players to play together on different types of devices (PCs, game consoles, mobile devices, and...

Launching the multiplayer Pangaea game in the editor

The first important thing you need to know is that Unreal Engine is internally designed based on the network multiplayer mechanism, which means that all games built with Unreal, irrespective of whether they are single-player or multiplayer, are client/server (CS) multiplayer games.

To verify whether our Pangaea game supports multiplayer mode, you can launch the game with two players in the Unreal Editor. To do that, click the Change Play Mode and Play Settings button from the toolbar and set Number of Players to 2:

Figure 10.4 – Setting the number of players

Figure 10.4 – Setting the number of players

Then, select Net Mode from the same drop-down menu and select Play As Listen Server:

Figure 10.5 – Setting the play mode as Play as Listen Server

Figure 10.5 – Setting the play mode as Play as Listen Server

Now, click the Play button (the green triangle) to launch the game. You should get two game windows (one in the viewport and another one as a separate window...

Understanding multiplayer game network modes

Network mode refers to a game application’s relationship to a multiplayer game session. A game instance can adopt any of the following game modes:

  • Listen server (host): In this mode, one player’s machine serves as both the game server and the local player’s game environment. The game running on the server is hosting a network multiplayer session, which accepts connections from remote clients. This mode is often used for casual cooperative and competitive multiplayer games.
  • Dedicated server: In this mode, the game is running as a server hosting a network multiplayer session. It accepts connections from remote clients but has no local players. The dedicated server mode is often used for large-scale multiplayer games.

A headless dedicated server is a server packaged without any graphic and audio, input, or other player-oriented features, so that the server runs more efficiently and uses less memory.

...

Handling network synchronizations

When you played the multiplayer Pangaea game, you would have noticed some bugs; for example, if you attacked on the client side, the player’s server avatar wouldn’t attack. These bugs occurred because our single-player code didn’t handle multiplayer synchronizations.

Before writing multiplayer code, we want to emphasize that you must be very clear in your mind whether the code will be executed on the server side, the client side, or both the server and client sides.

To make Pangaea playable as a multiplayer game, we need to do the following:

  • Notify player attacks with remote procedure calls (RPCs)
  • Sync actor variables to clients with replications
  • Update the character health bar with RepNotify
  • Process hits on the server
  • Spawn fireballs on the server side

Let’s look at how we can implement all of these listed actions.

Notifying player attacks with RPCs

In Pangaea, a player’...

Summary

This chapter demonstrated how to make a single-player game a multiplayer game in Unreal. The content we introduced in this chapter focuses on learning essential concepts and methods to follow to solve common multiplayer game issues. The knowledge you gained from this chapter can be a starting point that will help you continue learning about advanced multiplayer game development in the future.

In the first section, we introduced the concepts of single-player, local multiple, and network multiplayer games so that you got a basic sense of what is required for multiplayer gameplay.

Then, you learned how to launch the Pangaea game with two players (one listen server and one client) in the editor. Based on that, we explained multiplayer game net modes as well as identified some issues associated with multiplayer gameplay.

To solve issues in the multiplayer version game, you learned to use RPCs to notify the server and the other clients of attack actions, replicate actor...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Unreal Engine 5 Game Development with C++ Scripting
Published in: Aug 2023 Publisher: Packt ISBN-13: 9781804613931
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime}