Reader small image

You're reading from  Game Development Projects with Unreal Engine

Product typeBook
Published inNov 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781800209220
Edition1st Edition
Languages
Tools
Right arrow
Authors (4):
Hammad Fozi
Hammad Fozi
author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

Gonçalo Marques
Gonçalo Marques
author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working 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.
Read more about Gonçalo Marques

David Pereira
David Pereira
author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

Devin Sherry
Devin Sherry
author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry

View More author details
Right arrow

17. Remote Procedure Calls

Overview

In this chapter, you will be introduced to Remote Procedure Calls, which is another important multiplayer concept of Unreal Engine 4's Network Framework. You'll also learn how to use enumerations in Unreal Engine 4 and how to use bi-directional circular array indexing, which is a way to help you iterate arrays in both directions and be able to loop around when you go beyond its index limits.

By the end of this chapter, you'll understand how Remote Procedure Calls work to make the server and the clients execute logic on one another. You'll also be able to expose enumerations to the Unreal Engine 4 editor and use bi-directional circular array indexing to cycle through arrays.

Introduction

In the previous chapter, we covered some critical multiplayer concepts, including the server-client architecture, connections and ownership, roles, and variable replication. We also saw how the listen server is quicker to set up compared to the dedicated server but is not as lightweight. We used that knowledge to create a basic first-person shooter character that walks, jumps, and looks around.

In this chapter, we're going to cover Remote Procedure Calls (RPCs), which is another important multiplayer concept that allows the server to execute functions on the clients and vice versa. So far, we've learned variable replication as a form of communication between the server and the clients, but that won't be enough, because the server might need to execute specific logic on the clients that doesn't involve updating the value of a variable. The client also needs a way to tell its intentions to the server, so that the server can validate the action and...

Remote Procedure Calls

We've covered variable replication in Chapter 16, Multiplayer Basics, and, while a very useful feature, it is a bit limited in terms of allowing the execution of custom code in remote machines (client-to-server or server-to-client) for two main reasons:

  • The first one is that variable replication is strictly a form of server-to-client communication, so there isn't a way for a client to use variable replication to tell the server to execute some custom logic by changing the value of a variable.
  • The second reason is that variable replication, as the name suggests, is driven by the values of variables, so even if variable replication allowed the client-to-server communication, it would require you to change the value of a variable on the client to trigger a RepNotify functionality on the server to run the custom logic, which is not very practical.

To solve this problem, Unreal Engine 4 supports RPCs. An RPC works just like a normal...

Enumerations

An enumeration is a user-defined data type that holds a list of integer constants, where each item has a human-friendly name assigned by you, which makes the code easier to read. As an example, we could use an integer variable to represent the different states that a character can be in – 0 means it's idle, 1 means it's walking, and so on. The problem with this approach is that when you start writing code such as if(State == 0), it will become hard to remember what 0 means, especially if you have a lot of states, without using some documentation or comments to help you remember. To fix this problem, you should use enumerations, where you can write code such as if(State == EState::Idle), which is much more explicit and easier to understand.

In C++, you have two types of enums, the older raw enums and the new enum classes, introduced in C++11. If you want to use C++ enumerations in the editor, your first instinct might be to do it in the typical way,...

Bi-Directional Circular Array Indexing

Sometimes, when you use arrays to store information, you might want to iterate it in a bi-direction circular fashion. An example of this is the previous/next weapon logic in shooter games, where you have an array with weapons and you want to be able to cycle through them in a particular direction, and when you reach the first or the last index, you want to loop back around to the last and first index, respectively. The typical way of doing this example would be the following:

AWeapon * APlayer::GetPreviousWeapon()
{
  if(WeaponIndex - 1 < 0)
  {
    WeaponIndex = Weapons.Num() - 1;
  }
  else WeaponIndex--;
  return Weapons[WeaponIndex];
}
AWeapon * APlayer::GetNextWeapon()
{
  if(WeaponIndex + 1 > Weapons.Num() - 1)
  {
    WeaponIndex = 0;
  }
  else WeaponIndex++;
  return Weapons[WeaponIndex]...

Summary

In this chapter, you learned how to use RPCs to allow the server and the clients to execute logic on one another. We also learned how enumerations work in Unreal Engine 4 by using the UENUM macro and how to use bi-directional circular array indexing, which helps you iterate an array in both directions and loops around when you go beyond its index limits.

With the activity of this chapter complete, you'll have a basic playable game where players can shoot each other and switch weapons, but there is still more we can add to make it even more interesting.

In the next chapter, we'll learn where the instances of the most common gameplay framework classes exist in multiplayer, as well as learn about the Player State and Game State classes, which we haven't covered yet. We'll also cover some new concepts in the game mode that are used in multiplayer matches, as well as some useful general-purpose, built-in functionality.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Game Development Projects with Unreal Engine
Published in: Nov 2020Publisher: PacktISBN-13: 9781800209220
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.
undefined
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 $15.99/month. Cancel anytime

Authors (4)

author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working 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.
Read more about Gonçalo Marques

author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry