UE4 Deck of Cards

C++ and UE4 Interface - Page 1

We want to write code that interfaces with blueprints in Unreal Engine and exposes them to various technical staff around the team including level designers, lighters, artists, audio professionals etc... This is a look at how to write classes that integrate well with blueprints and the UE4 editor.

Otter dancing with a fish

You will need to install either Visual Studio Community 19 on the PC with C++ drivers or XCode on the mac. You will need to install the latest version of UE4 4.25.x by downloading the Epic Games Launcher. You will also need a GitHub account which is free to sign up for as we will be using version control.

1. Getting Set-Up

Lets start by getting a project and up and running. Lets add a material for a card and set it up in an unlit level with a camera.


Setting up our Dev Environment

Create a new project in UE4 and pick type Games and press the Next button:


Select Blank

Select Blank and press the Next button:


C++ Blank

Select C++ Basic, no starter content project and pick a directory to save it in. Call the project DeckOfCardsI then press the Create Project button.


Add Folders

Press the Add New button and add 4 new folders called Blueprints, Levels, Materials and Textures.


Download Playing Cardszip and unzip the folder. Drag all the .png files into the Textures folder. Take a moment to look at the names. I have very consistent naming so that we can in a loop import the textures dynamically.


Non Lit Game

Now this is a 2-D game and we will not be lighting it conventionally like a 3-D game. In fact we will have no lights in the scene. Click on the Add New button and select Material:



Name this material M_Card and double click it to enter the material editor.


Send to Emissive

Now we right click on the graph and select a Texture Sample node. Take the top RGB output pin and place it into the Emissive Color node in the M_Card node. Since there are no lights this is a self lit texture (all will be lit with the same intensity). Then select any of the card textures. Look at the preview window and look at the texture on a flat plane. It is squished but we will be fixing that.


Convert to Parameter

Now we want to be able to assign different card textures to different cards dynamically at run time. This means we need to manipulate this node. We cannot unless we make it a parameter that we can edit. Right click on the Texture Sample node and select Convert to Parameter so we can edit it in a blueprint or in C++.


Name Parameter

Now you can give this parameter a name and call it Card_Texture. When you finish a material you always have to press the Apply button so that the matelerial is rendered and usable otherwise it will not affect the actor.


Start Level

Start a new empty level with no objects in the scene. Call it L_Card_Table.


Set Default Level

Now lets set this level as the default level. Right click on Edit | Project Settings and select Maps & Modes and change both the Editor Startup Map and Game Default Map to L_Card_Table.


Add Camera

We need to add a camera to the scene. Type Camera into the Modes tab and drag a camera into the scene.


Center Location of Camera

Press the yellow arrow next to Location and press it to reset the position to 0,0, 0.0, 0.0.


Rotate To Point Down

Now since Unreal is Z up, I want my 2-d level to be on the X Y plane. So move the camera up the Z axis, to around 310 and then rotate on the Y axis by 270 degrees to shoot downwards.


Orhtographic Camera

Since this is 2-D we don't want a perspective camera, we want an orthographic one. This means that objects in front of the camera do not scale, they are always the same size. So we can stack our cards in Z without affecting the scale of the cards.