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.
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.
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.
1-1
Setting up our Dev Environment
Create a new project in UE4 and pick type Games and press the Next button:
1-3
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.
1-4
Add Folders
Press the Add New button and add 4 new folders called Blueprints
, Levels
, Materials
and Textures
.
1-5
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.
1-6
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:
1-8
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.
1-9
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++.
1-10
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.
1-12
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.
1-13
Add Camera
We need to add a camera to the scene. Type Camera into the Modes tab and drag a camera into the scene.
1-14
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
.
1-15
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.
1-16
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.