Unreal Game Engine – C++ Programming – Quick Start Guide

C++ (pronounced cee plus plus) is a general purpose programming language. It has imperative, object-oriented and generic programming features, while also providing the facilities for low level memory manipulation.

Unreal Engine does not have an internal code editor, you need to install Visual Studio od Visual studio Express.

1. Install the latest version of Internet Explorer
2. Install Visual Studio Express
3. Run Visual Studio

Increase the width of the Solution Configurations dropdown menu:
a. Right-click on the toolbar and select Customize (Personalizza) at the bottom of the menu that appears.
b. Click on the Commands tab (Comandi).
c. Select the Toolbar (Barra degli strumenti) radio button.
d. In the dropdown next to Toolbar, choose Standard.
e. In the Controls list at the bottom, select the Solution Configurations control (Configurazioni soluzione).
f. Click Modify Selection (Modifica selezione) on the right. Set the Width (larghezza) to “200”.
g. Click Close. Your toolbar should update immediately.

Add the Solution Platforms dropdown
Find the right-most button on the Standard toolbar, which opens a dropdown menu that will allow you to add and remove buttons from the toolbar.
Click the dropdown button, hover over Add or Remove Buttons, and then click on Solution Platforms (Piattaforme soluzione) to add the menu to the toolbar.

Turn off the Error List window
With Unreal Engine, the Error List can display false error information.

a. Close the Error List window if it is open.
b. From the Tools menu, open the Options dialog (Strumenti> Opzioni).
c. Select Projects and Solutions (Progetti e soluzioni) and uncheck Always show error list if build finishes with error (Mostra sempre Elenco errori se la compilazione finisce con errori).
d. Click OK

Create a New Project

1. Open Unreal Editor> New Project> Blank, name it ‘CodeTestProject’ uncheck ‘Include starter content’, click on ‘Create Project’ button

Add a New Class

1. MAIN TOP MENU> File> Add Code to Project> Actor
2. Name it ‘HelloWorldPrinter’> click ‘Create Class’ button, it will create in your project folder:
– HelloWorldPrinter.h (header)
– HelloWorldPrinter.cpp (c plus plus source)
3. In the next floating window click ‘Yes’ to edit now, Unreal will run Visual Studio Express

Visual Studio takes several minutes to analysing files, includes etc…, at the end you will se the message ‘Ready’ (Pronto), in the RIGHT COLUM> Solution Explorer (Esplora Soluzioni) you will see Games/CodeTestProject

Write the code:

HelloWorldPrinter.h


#pragma once

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

/**
 * 
 */
UCLASS() // Questo rende Unreal Engine consapevoli della vostra nuova classe
class CODETESTPROJECT_API AHelloWorldPrinter : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY() // Questo rende Unreal Engine consapevoli della vostra nuova proprietà
	int32 MyNumber; // declare an integer variable

	virtual void BeginPlay() override;// Questo codice dichiara una funzione, ma lo fa eseguendo l'override di una funzione dalla classe padre.


};// END UCLASS

HelloWorldPrinter.cpp


#include "CodeTestProject.h"
#include "HelloWorldPrinter.h" 

//Your class constructor
AHelloWorldPrinter::AHelloWorldPrinter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	MyNumber = 12;
}

// Dichiara la funzione - eseguita in BeginPlay() che è la funziona che unreal esegue all'inizio del game
void AHelloWorldPrinter::BeginPlay()
{
	Super::BeginPlay();

	if (GEngine) // Controllo se è valido l'oggetto globale GEngine
	{
		// Visualizza il testo a video
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Hello World!"));
		// Visualizza la variabile MyNumber
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(MyNumber));
	}
}

Save All

Compile the code

1. RIGHT COLUMN> Solution Explorer (Eslora Soluzioni)> RMB over yourproject (|++|CodeTestProject)> Build (Compila)

The process can take several minutes because it compile all the dependencies.

Using the New Class

1. Close Unreal Editor
2. Reopen the Unreal Editor and reload the Project
3. MAIN TOP MENU> Class Viewer> Filters> uncheck ‘Blueprint Bases Only’, search ‘HelloWorldPrinter’
4. DRAG and DROP Actor>HelloWorldPrinter (the Sphere icon), from the Class Viewer into 3D Viewport.
5. Play

Change the Class

1. Close Unreal Editor (if you do not close the Unreal Editor, Visual Studio can not overwrite the old file)
2. Inside Visual Studio open HelloWorldPrinter.cpp
3. Change … Yellow, TEXT(“Hello World!”) to …Yellow, TEXT(“Hello World Two!”)
4. RMB over yourproject (|++|CodeTestProject)> Build (Compila), the process takes only few seconds.
5. Reopen Unreal Editor
6. DRAG AND DROP Actor>HelloWorldPrinter (the Sphere icon), from the Class Viewer into 3D Viewport.
5. Play

Reference: https://docs.unrealengine.com/latest/INT/Programming/QuickStart/1/index.html

Editing an existing Project on the fly

0. Open Visual Studio> TOP TOOLBAR> Solutions Configurations (Configurazioni soluzioni)> DebugGame Editor
Questo significa che possiamo debuggare e aprire il progetto direttamente

1. Open Visual Studio Express> MAIn TOP MENU> File> Open Project (Apri Progetto)> select ‘CodeTestProject.sln’
2. RIGHT COLUMN> Solutions Explorer> click over Games/CodeTestProject/Source/HelloWorldPrinter.cpp
3. Change the script and save it
4. RIGHT COLUMN> Solutions Explorer> RMB over Games/CodeTestProject> Debug> Run New Instance (Avvia Nuova Istanza)

5. Unreal Enditor will be opened

Play to see changes

6. Switch to Visual Studio, change the script, save it.
7. Switch to Unreal Editor, MAIN TOP TOOLBAR> Compile> Recompile Game Code (Recompile and Reload C++ code on the fly)

Play to see changes
4. File> Save HelloWorldPrinter.cpp

For italian people: come funziona?

1. Visual Studio viene settato per permettere il debug direttamente all’interno di Unreal editor con ‘Configurazioni soluzioni> DebugGame Editor’
2. da visual Studio creo un ponte verso Unreal Editor con ‘Avvia Nuova Istanza’
3. da Unreal Editor posso ricompilare al volo direttamente dall TOOLBAR superiore con ‘Recompile Game Code’