Getting started with Unreal Engine and C++

Modern game engines are incredibly powerful, being able to render millions of objects while running complex background processes such as physics engines. Being multi-platform capable has become the norm, too. As a result, game engines have become popular also for “serious” work such as 3D simulations. The two most popular game engines are Unity and Unreal Engine. I’ve done some testing with the open source engine Godot last year. I made some quick initial progress, but then struggled to move further as the available off-the-shelf functionality is quite limited. I’ve fiddled with Unity in the past. I like how tightly integrated it is with C#, but I didn’t find it particularly easy to do basic things like drawing lines.

Unreal Engine

Unreal Engine, by Epic Games, takes its name from the Unreal series of first person shooters. Today it is probably best known as the engine powering Fortnite, but Epic and UE also have a strong holding in reality modelling and simulation with RealityScan and TwinMotion.

After a couple of years of coding predominantly in C#, I switched back to C++ for point cloud processing in 2022 for various reasons – better performance, better library availability, and to make a clean start after starting a new company. Unlike Unity, Unreal Engine uses C++ as its main programming language, so it appears to be a natural fit for me. The other big reason for Unreal Engine is that is comes with a powerful Point Cloud plugin that completely eliminates the need to write low-level point cloud code.

Getting started with C++ in UE

The downside is that C++ is not the only programming language used with Unreal Engine. In fact, Epic heavily promotes its Blueprint visual programming language as a supposedly easier way of coding UE, and much of the documentation, many examples and forum posts thus use Blueprints instead of C++. So why bother with C++ then and not stick to Blueprints. I can give you at least two reasons:

  • Some low-level functionality, such as much of the point cloud functionality, is not exposed to Blueprints and only usable with C++.
  • While visual programming languages have their charm, I find them clunky to use ever since I first got to experience them with LabView more than 20 years ago. They are fine for connecting together self-contained function blocks, but I have a strong dislike for how convoluted simple things like a loop or basic computations are with them.

I’ve also read that pure C++ offers a performance advantage, but I haven’t confirmed that claim.

The logical starting point for your journey is Epic’s documentation:

  • Programming with C++ is the section where you should start, as it explains how to setup Visual Studio for use with Unreal Engine.
  • A bit hidden away, but very useful are the C++ Programming Tutorials. I can especially recommend the Programming Quick Start and First Person Shooter Tutorial.
  • UE comes with several sample projects that can be used as starting point for a project of your own. I recommend taking a look at all of them to find out how various things work. They differ in how much they use C++. Some are very Blueprint-heavy, but the First Person Shooter sample uses C++ almost exclusively, including a full example of how to use the Enhanced Input module.
  • The C++ API Reference lists all C++ classes. Unfortunately, in many cases there are no actual usage examples, so it will take some experimenting to find out how things actually work.

Another useful resource is this collection of information on Github.

Many questions have been asked and answered on the forums, so Google should be able to point you into the right direction. Be sure to add C++ to your search term to not get Blueprint stuff only. But don’t ignore Blueprints completely either – most nodes have equivalent C++ methods.

I’ve also had limited success by asking ChatGPT. Like always with generative AI, results can be hit or miss. ChatGPT generated a class for drawing splines that worked immediately and only produced a few warnings that were easily eliminated. On the other hand, if you try doing something that no-one has tried before and published code for, don’t expect a useable results. After figuring it out myself, I asked ChatGPT to write me some code to read point clouds in UE, and the results (even after I asked explicitly to use the Lidar Point Cloud plugin) weren’t even close to usable.

Player Controllers, Characters, Pawns, and Actors

UE makes use of different classes from which to derive functionality. The Player Controller takes input, so most input-related logic will go here. This can be used to instantiate and work with three different types of objects:

  • Characters represent the player. Even if you’re creating a simulation or a data viewer instead of a game, a character-derived class will be used for controlling the camera.
  • Pawns are objects that can be controlled by the player/user.
  • Actors are objects that are not under the direct control of the player/user.

All three classes have plenty of shared functionality, but there are subtle differences that will make a specific one the best fit.

Don’t give up

I’m not claiming that programming Unreal Engine with C++ is easy. The combination of high complexity and lacking documentation make for a steep learning curve, so I wouldn’t recommend to someone who is new to C++. As an example, I spent a couple of hours trying to bind an actor to an Enhanced Input Action, without success – until I used a different template, without a Blueprint Player Controller that apparently intercepted all input. So if something that should work doesn’t, trying it again in a bare-bones template might be worth a try. A bit of understanding of Blueprints is helpful, too, as some functions are much easier added with a few Blueprint nodes than C++ code.

 

Een reactie plaatsen

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *