Warriors Board

Gameplay Programming

Overview

About the project

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam fermentum ex in suscipit eleifend. Suspendisse a odio non orci euismod scelerisque. Nam sapien arcu, tristique vitae risus in, iaculis dictum diam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam fermentum ex in suscipit eleifend. Suspendisse a odio non orci euismod scelerisque. Nam sapien arcu, tristique vitae risus in, iaculis dictum diam. Aenean vulputate urna eget est vehicula tincidunt.

Date
January 1, 2022
My Role
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Setup

Creating the C++/Blueprints game project

After installing a version of Unreal Engine, we are ready to create a game project for the Memory Game. You can do it by clicking in Launch just right below the version number of the installed engine version.

After presenting the Unreal Project Browser, select the game type we are building and choose Blank Project setting the project defaults to C++ and quality preset to Scalable with Starter Content toogle checked as shown in the image below.

Do not forget to set the name of the project as you like. Here I put simply "MemoryGame".

Hit Create button.

Creating the game map

 After loading the default game map, you will see the default terrain that everytime the engine starts it loads that up.

We are going to create our level or map as it is known in unreal engine.

Just hit File -> New Level... as shown below.

Then choose a basic map type.

After loading the basic map layout, hit Ctrl+Space to display the Content Browser. It is the place where the project files are organized. Let's create the initial following folder hierarchy.

Create a folder by clicking the right mouse button to invoke the context menu and choose New Folder.

Now let's save the map under Content -> MemoryGame -> Maps

Game Setup is done. We are ready to get started implementing the game mechanics.

The map looks like the following image.

Creating the gameplay

Creating the Game Mode Base

Game Mode Base is the class responsible for defining the game being played, its characters, its user interfaces, its rules, scoring and other game properties types.

Game Mode Base is one of the main classes that makes up the Gameplay Framework of the Unreal Engine. It is a collection of classes that implement gameplay functionality in unreal projects.

Tools > Add new C++ class...

 Scroll down the panel until you find the Game Mode Base class option.

 Let's rename it MemoryGameModeBase.

After some minutes, it is going to open up your IDE which is defined in the Editor Preferences. You can choose another editor such as Rider, Visual Studio, Visual Code.

For this tutorial in particular I will be using Rider for Unreal Engine.

If you are using the Rider editor it will ask your permission to install the Rider Link Unreal Editor plugin.

Install it in game folder as indicated. Known issues occur when installing in Engine folder.

Once we have our game mode base class defined, from your IDE hit run to build the code.

It is going to have a basic default code generated by unreal engine.

Simply run the code to build up the  up the Unreal Editor. Every modification to vthe source code it needs to rebuild again to have modifications updated and reflected in the gameplay.

In the Content Browser, it is going to be added to the Content folder hierarchy the C++ code folder where all source files are going to be located for this project.

   

In Unreal Game projects, the Game Mode Base class can be created from C++ or from Visual Scripting called Blueprints and even combined.

Blueprints

Visual Scripting tool to create unit custom functionalities and behaviors to increase game features just like plain source code files in C++.

In this tutorial, we are going to use the combined approach by creating the blueprint Game Mode Base class from our equivalent C++ class.

Add blueprint of the type Game Mode Base class and rename it MemoryGameModeBase.

 Double click to open the blueprint editor, you can click on Full Blueprint Editor to show all editor features.

And go to File > Reparent Blueprint

Now choose the C++ created class.

After confirming the Blueprint is created.

Using this approach the Game Mode Base class can be edited from different professionals as the Game Designer directly from the editor without having to open an IDE, it smooths the pipeline processes.

             

Working with C++ and Blueprints

Now that we have our game mode base class in both C++ and Blueprints, let's see how we can work with them integrated.

The objective here is to expose variables created in source  code to be visible to the Game designer or another person which needs to tweak values to test gameplay.

Exposing variables on Blueprints makes not only a smooth game production pipeline but also helps different professionals work together efficiently without having to worry about external tools which is not part of their daily activities.

Let's open our MemoryGameMode.cpp and write the following code:

CODE

#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class AMyActor : public AActor
{
    GENERATED_BODY()

public:
    // Sets default values for this actor's properties
    AMyActor();

    // Called every frame
    virtual void Tick( float DeltaSeconds ) override;

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
};

To expose variables to Blueprints it is used the C++ macro

MACRO with modifiers

Then hit run to build the Unreal Editor with the new modifications to the Blueprint.

When loaded, open the MemoryGameMode Blueprint and look for the created variables in source code.

To use the Game Mode Base class created to be used during gameplay click on Settings > Select

PICTURE

Hit Play to run the game and press F8 detach the main camera and enable the mouse to select the GameModeBase in the outline view.

When selected the blueprint the created variable on source code is going to be visible in the outline to be modified.

Let's print the variable on the screen using blueprint nodes.

Visual Scripting works by connecting different nodes to create instructions to run during gameplay.

Everything starts with the BeginPlay node where it is called just after the Game starts to run.

Let's print the result of the variable created by printing using the node Print. You can invoke by right clicking on

mouse button to appear the context menu and typing print. It is going to show up the print node.

Connect the Begin Play node to the Print node. To get the value of the variable exposed click on the name of the

variable and drag to the blueprint view. It is going to appear Get or Set variable, choose Get and connect it to the

Print message node.

Done!

When you hit Run it is going to present the value of the variable exposed on the screen.

LESSON

Create another type of variables in different categories to be exposed on variables.

   2.3 - Creating the card actor

CONCEPT

The actor class is every object that can be placed in the Game scene whether it has a visual representation or not.

Let's create a class actor by creating a C++ class actor . It will load this new class in your IDE.

PICTURE

The actor class is a base class for many classes in Unreal code base and makes up many of the more specialized classes of the engine. Examples are character, pawn, static mesh actor classes.

For this class we are going to create some variables to be exposed in the Editor and create one function to simulate when the card flips.

CODE

When finish editing build the code to open up the unreal editor.

  // my first program in C++
  #include 
  using namespace std;

  int main ()
  {
    cout << "Hello World!";
    return 0;
  }