For C++ Programmers
To use Blueprint scripting, you only need Unreal Engine. All the features you need are built in.
To write code in C++, download Visual Studio on Windows, or install Xcode on macOS. When you first create a new C++ project in Unreal Engine (or add C++ code to an existing project), Unreal Engine will automatically create Visual Studio project files for you.
There are two ways to access Visual Studio from your Unreal Engine project:
-
In the Content Browser, double-click a C++ class to open it in Visual Studio.
-
From the main menu, go to Tools > Open Visual Studio. This option only appears if your project contains at least one C++ class.
One important difference in Unreal Engine: You will sometimes have to manually refresh your Visual Studio project files (for example, after downloading a new version of Unreal Engine, or when manually making changes to source file locations on disk.) You can do this in two ways:
-
From Unreal Engine's main menu, go to Tools > Refresh Visual Studio Project.
-
Right-click the .uproject file in your project's directory and select Generate Visual Studio project files.
Writing Event Functions (Start, Update, etc.)
If you previously worked with MonoBehaviors, you should be familiar with methods such as Start, Update, and OnDestroy. Below is a comparison between a Unity behavior and its equivalent for Unreal Engine Actors and Components.
In Unity, you might have a simple component that looks like this:
public class MyComponent : MonoBehaviour
{
void Start() {}
void OnDestroy() {}
void Update() {}
}
In Unreal Engine, you can write code on the Actor itself rather than only coding new component types. This is actually very common and useful.
Unreal Engine Actors have a similar set of methods to Unity's Start, OnDestroy, and Update functions. These are shown below:
C++
UCLASS()
class AMyActor : public AActor
{
GENERATED_BODY()
// Called at start of game.
void BeginPlay();
// Called when destroyed.
void EndPlay(const EEndPlayReason::Type EndPlayReason);
// Called every frame to update this actor.
void Tick(float DeltaSeconds);
};
Blueprint
Components in Unreal Engine contain different functions. Here is a basic example:
C++
UCLASS()
class UMyComponent : public UActorComponent
{
GENERATED_BODY()
// Called after the owning Actor was created
void InitializeComponent();
// Called when the component or the owning Actor is being destroyed
void UninitializeComponent();
// Component version of Tick
void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction);
};
Blueprint
Remember, in Unreal Engine, you must call the parent class's version of the method.
For example, in Unity C# this would be called base.Update(), but in Unreal Engine C++ you will use Super::TickComponent():
void UMyComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
// Custom tick stuff here
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
In C++, some classes use the prefix A, while others use the prefix U. A indicates an Actor subclass, whereas U indicates an Object subclass. Another common prefix is F, which is used for most plain data structures and non-UObject classes.